X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FdeleteArchivedFiles.php;h=af05a81dee94cb12c43ab2b05b786d5ef27e47aa;hb=188c8966404cec56fcace874de57330abedb7129;hp=d07a8d4c7553fcdc5e8b2ca16940d8ad5d5631df;hpb=4b73a8b6fbb6da651af850a7d667e6e8d59e6fce;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/deleteArchivedFiles.php b/maintenance/deleteArchivedFiles.php index d07a8d4c75..af05a81dee 100644 --- a/maintenance/deleteArchivedFiles.php +++ b/maintenance/deleteArchivedFiles.php @@ -54,7 +54,7 @@ class DeleteArchivedFiles extends Maintenance { $this->output( "Searching for and deleting archived files...\n" ); $res = $dbw->select( 'filearchive', - [ 'fa_id', 'fa_storage_group', 'fa_storage_key', 'fa_sha1' ], + [ 'fa_id', 'fa_storage_group', 'fa_storage_key', 'fa_sha1', 'fa_name' ], '', __METHOD__ ); @@ -67,9 +67,19 @@ class DeleteArchivedFiles extends Maintenance { continue; } + /** @var LocalFile $file */ + $file = $repo->newFile( $row->fa_name ); + try { + $file->lock(); + } catch ( LocalFileLockError $e ) { + $this->error( "Could not acquire lock on '{$row->fa_name}', skipping\n" ); + continue; + } + $group = $row->fa_storage_group; $id = $row->fa_id; - $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key; + $path = $repo->getZonePath( 'deleted' ) . + '/' . $repo->getDeletedHashPath( $key ) . $key; if ( isset( $row->fa_sha1 ) ) { $sha1 = $row->fa_sha1; } else { @@ -96,6 +106,7 @@ class DeleteArchivedFiles extends Maintenance { $this->output( "Notice - file '$key' is still in use\n" ); } elseif ( !$repo->quickPurge( $path ) ) { $this->output( "Unable to remove file $path, skipping\n" ); + $file->unlock(); continue; // don't delete even with --force } else { $needForce = false; @@ -105,12 +116,14 @@ class DeleteArchivedFiles extends Maintenance { if ( $this->hasOption( 'force' ) ) { $this->output( "Got --force, deleting DB entry\n" ); } else { + $file->unlock(); continue; } } $count++; $dbw->delete( 'filearchive', [ 'fa_id' => $id ], __METHOD__ ); + $file->unlock(); } $this->commitTransaction( $dbw, __METHOD__ );