From: Aaron Schulz Date: Wed, 1 May 2013 01:42:03 +0000 (-0700) Subject: Reduced memory usage a bit for copyFileBackend.php with --missingonly. X-Git-Tag: 1.31.0-rc.0~19758^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22config_fonctions%22%2C%20%22image_process=%24process%22%29%20.%20%22?a=commitdiff_plain;h=f8af77dd9dd59b2aeaf849596d0d2fb14fe46675;p=lhc%2Fweb%2Fwiklou.git Reduced memory usage a bit for copyFileBackend.php with --missingonly. Change-Id: Iae650b5c3a5f99c5b2e31e29c276957ea6b8bb50 --- diff --git a/maintenance/copyFileBackend.php b/maintenance/copyFileBackend.php index f2c4ac5414..fe422b38a3 100644 --- a/maintenance/copyFileBackend.php +++ b/maintenance/copyFileBackend.php @@ -79,24 +79,28 @@ class CopyFileBackend extends Maintenance { // 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 } + // Get the list of destination files + $relFilesDstSha1 = array(); foreach ( $dstPathsRel as $dstPathRel ) { - $relFilesDst[] = $dstPathRel; + $relFilesDstSha1[sha1( $dstPathRel )] = 1; + } + unset( $dstPathsRel ); // free + // Get the list of missing files + $missingPathsRel = array(); + foreach ( $srcPathsRel as $srcPathRel ) { + if ( !isset( $relFilesDstSha1[sha1( $srcPathRel )] ) ) { + $missingPathsRel[] = $srcPathRel; + } } + unset( $srcPathsRel ); // free // Only copy the missing files over in the next loop - $srcPathsRel = array_diff( $relFilesSrc, $relFilesDst ); + $srcPathsRel = $missingPathsRel; $this->output( count( $srcPathsRel ) . " file(s) need to be copied.\n" ); - unset( $relFilesSrc ); - unset( $relFilesDst ); } $batchPaths = array();