jenkins-bot has submitted this change and it was merged.

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). If the file does not exist, allow the
exception from Cdb\Reader to buuble up.

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

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

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/TrustedXFF.body.php b/TrustedXFF.body.php
index 166cb7d..02031d8 100644
--- a/TrustedXFF.body.php
+++ b/TrustedXFF.body.php
@@ -36,9 +36,6 @@
        function getCdbHandle() {
                if ( !$this->cdb ) {
                        global $wgTrustedXffFile;
-                       if ( !file_exists( $wgTrustedXffFile ) ) {
-                               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: merged
Gerrit-Change-Id: I095ce9ccf2a2d755e5eeb0ffe4bb94481f3b0c0b
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/TrustedXFF
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to