From: Aaron Schulz Date: Fri, 10 Aug 2012 05:23:44 +0000 (-0700) Subject: [FileBackend] Added option for copy script to skip non-UTF8 filenames. X-Git-Tag: 1.31.0-rc.0~22776^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/modifier.php?a=commitdiff_plain;h=eb65b839f8c8329198c9a1bf0b089b6c3a973ebd;p=lhc%2Fweb%2Fwiklou.git [FileBackend] Added option for copy script to skip non-UTF8 filenames. Change-Id: I9b48012d890c2c4589984576a31d84dde535ad5b --- diff --git a/maintenance/copyFileBackend.php b/maintenance/copyFileBackend.php index 70a923262e..2363d40ae3 100644 --- a/maintenance/copyFileBackend.php +++ b/maintenance/copyFileBackend.php @@ -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... }