X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FcopyFileBackend.php;h=2363d40ae3eb095cab486db8026ea1e17571d237;hb=c735d67ee3e806140cace16779f33c150f48bea2;hp=8db0a7f4bd92650da2408526c59c47db887a9497;hpb=46992c8bb4e520e75b128936ba790b0475c9c73e;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/copyFileBackend.php b/maintenance/copyFileBackend.php index 8db0a7f4bd..2363d40ae3 100644 --- a/maintenance/copyFileBackend.php +++ b/maintenance/copyFileBackend.php @@ -44,6 +44,8 @@ class CopyFileBackend extends Maintenance { $this->addOption( 'subdir', 'Only do items in this child directory', false, true ); $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 ); } @@ -55,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 != '' ) { @@ -65,12 +71,34 @@ class CopyFileBackend extends Maintenance { $this->output( "Doing container '$container'...\n" ); } - $dir = $src->getRootStoragePath() . "/$backendRel"; - $srcPathsRel = $src->getFileList( array( 'dir' => $dir ) ); + $srcPathsRel = $src->getFileList( array( + 'dir' => $src->getRootStoragePath() . "/$backendRel" ) ); if ( $srcPathsRel === null ) { $this->error( "Could not list files in $container.", 1 ); // die } + // Do a listing comparison if specified + if ( $this->hasOption( 'missingonly' ) ) { + $relFilesSrc = array(); + $relFilesDst = array(); + foreach ( $srcPathsRel as $srcPathRel ) { + $relFilesSrc[] = $srcPathRel; + } + $dstPathsRel = $dst->getFileList( array( + 'dir' => $dst->getRootStoragePath() . "/$backendRel" ) ); + if ( $dstPathsRel === null ) { + $this->error( "Could not list files in $container.", 1 ); // die + } + foreach ( $dstPathsRel as $dstPathRel ) { + $relFilesDst[] = $dstPathRel; + } + // Only copy the missing files over in the next loop + $srcPathsRel = array_diff( $relFilesSrc, $relFilesDst ); + $this->output( count( $srcPathsRel ) . " file(s) need to be copied.\n" ); + unset( $relFilesSrc ); + unset( $relFilesDst ); + } + $batchPaths = array(); foreach ( $srcPathsRel as $srcPathRel ) { // Check up on the rate file periodically to adjust the concurrency @@ -109,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... } @@ -117,10 +148,16 @@ class CopyFileBackend extends Maintenance { $fsFile = $src->getLocalReference( array( 'src' => $srcPath, 'latest' => 1 ) ); if ( !$fsFile ) { $this->error( "Could not get local copy of $srcPath.", 1 ); // die + } elseif ( !$fsFile->exists() ) { + // FSFileBackends just return the path for getLocalReference() and paths with + // illegal slashes may get normalized to a different path. This can cause the + // local reference to not exist...skip these broken files. + $this->error( "Detected possible illegal path for $srcPath." ); + continue; } $fsFiles[] = $fsFile; // keep TempFSFile objects alive as needed // Note: prepare() is usually fast for key/value backends - $status = $dst->prepare( array( 'dir' => dirname( $dstPath ) ) ); + $status = $dst->prepare( array( 'dir' => dirname( $dstPath ), 'bypassReadOnly' => 1 ) ); if ( !$status->isOK() ) { $this->error( print_r( $status->getErrorsArray(), true ) ); $this->error( "Could not copy $srcPath to $dstPath.", 1 ); // die @@ -131,7 +168,11 @@ class CopyFileBackend extends Maintenance { } $t_start = microtime( true ); - $status = $dst->doOperations( $ops, array( 'nonJournaled' => 1 ) ); + $status = $dst->doQuickOperations( $ops, array( 'bypassReadOnly' => 1 ) ); + if ( !$status->isOK() ) { + sleep( 10 ); // wait and retry copy again + $status = $dst->doQuickOperations( $ops, array( 'bypassReadOnly' => 1 ) ); + } $ellapsed_ms = floor( ( microtime( true ) - $t_start ) * 1000 ); if ( !$status->isOK() ) { $this->error( print_r( $status->getErrorsArray(), true ) );