Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/250207

Change subject: Avoid a needless and racy file_exists() check
......................................................................

Avoid a needless and racy file_exists() check

Instead of calling file_exists() and then trying to open the CDB file, just go
ahead and try to open it and see if it suceeds. This is both more efficient
(because it avoids the file_exists()) and more reliable (because it is not
subject to the race condition whereby the file is removed between the
file_exists() and the open calls).

EAFP :) (http://stackoverflow.com/a/11360880)

Change-Id: I095ce9ccf2a2d755e5eeb0ffe4bb94481f3b0c0b
---
M TrustedXFF.body.php
1 file changed, 2 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TrustedXFF 
refs/changes/07/250207/1

diff --git a/TrustedXFF.body.php b/TrustedXFF.body.php
index 166cb7d..aa05115 100644
--- a/TrustedXFF.body.php
+++ b/TrustedXFF.body.php
@@ -36,10 +36,10 @@
        function getCdbHandle() {
                if ( !$this->cdb ) {
                        global $wgTrustedXffFile;
-                       if ( !file_exists( $wgTrustedXffFile ) ) {
+                       $this->cdb = MediaWiki\quietCall( 'CdbReader::open', 
$wgTrustedXffFile );
+                       if ( $this->cdb === false ) {
                                throw new MWException( 'TrustedXFF: hosts file 
missing. You need to download it.' );
                        }
-                       $this->cdb = CdbReader::open( $wgTrustedXffFile );
                }
                return $this->cdb;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/250207
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I095ce9ccf2a2d755e5eeb0ffe4bb94481f3b0c0b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TrustedXFF
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to