X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2FcopyFileBackend.php;h=aebdee175f3f3e627886d437debf56402665e962;hb=95686fdb6ae34c7db75b0a519701a0c09c672ff6;hp=70a923262e83f9804009257e070473453fd754ae;hpb=b7ce0372b06fec4f9b3f2c2c8b2a794e5ab742f3;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/copyFileBackend.php b/maintenance/copyFileBackend.php index 70a923262e..aebdee175f 100644 --- a/maintenance/copyFileBackend.php +++ b/maintenance/copyFileBackend.php @@ -21,7 +21,7 @@ * @ingroup Maintenance */ -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); +require_once( __DIR__ . '/Maintenance.php' ); /** * Copy all files in one container of one backend to another. @@ -45,6 +45,7 @@ class CopyFileBackend extends Maintenance { $this->addOption( 'ratefile', 'File to check periodically for batch size', false, true ); $this->addOption( 'skiphash', 'Skip SHA-1 sync checks for files' ); $this->addOption( 'missingonly', 'Only copy files missing from destination listing' ); + $this->addOption( 'utf8only', 'Skip source files that do not have valid UTF-8 names' ); $this->setBatchSize( 50 ); } @@ -56,6 +57,10 @@ class CopyFileBackend extends Maintenance { $rateFile = $this->getOption( 'ratefile' ); + if ( $this->hasOption( 'utf8only' ) && !extension_loaded( 'mbstring' ) ) { + $this->error( "Cannot check for UTF-8, mbstring extension missing.", 1 ); // die + } + $count = 0; foreach ( $containers as $container ) { if ( $subDir != '' ) { @@ -132,7 +137,10 @@ class CopyFileBackend extends Maintenance { foreach ( $srcPathsRel as $srcPathRel ) { $srcPath = $src->getRootStoragePath() . "/$backendRel/$srcPathRel"; $dstPath = $dst->getRootStoragePath() . "/$backendRel/$srcPathRel"; - if ( $this->filesAreSame( $src, $dst, $srcPath, $dstPath ) ) { + if ( $this->hasOption( 'utf8only' ) && !mb_check_encoding( $srcPath, 'UTF-8' ) ) { + $this->error( "Detected illegal (non-UTF8) path for $srcPath." ); + continue; + } elseif ( $this->filesAreSame( $src, $dst, $srcPath, $dstPath ) ) { $this->output( "Already have $srcPathRel.\n" ); continue; // assume already copied... }