jenkins-bot has submitted this change and it was merged.

Change subject: Add missing file locks to deleteArchivedFiles.php
......................................................................


Add missing file locks to deleteArchivedFiles.php

Change-Id: I512ce5a1a4f00039fbe26f1c5cd1aec655eea263
---
M maintenance/deleteArchivedFiles.php
1 file changed, 15 insertions(+), 2 deletions(-)

Approvals:
  MaxSem: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/maintenance/deleteArchivedFiles.php 
b/maintenance/deleteArchivedFiles.php
index d07a8d4..af05a81 100644
--- a/maintenance/deleteArchivedFiles.php
+++ b/maintenance/deleteArchivedFiles.php
@@ -54,7 +54,7 @@
                $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 @@
                                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 @@
                                $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 @@
                                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__ );

-- 
To view, visit https://gerrit.wikimedia.org/r/300216
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I512ce5a1a4f00039fbe26f1c5cd1aec655eea263
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to