Skip to content

Commit

Permalink
Bugfix: renaming an existing file after a fsck started could result i…
Browse files Browse the repository at this point in the history
…n a "lost" file (until fsck ran again for this file, then it came back)
  • Loading branch information
gboudreau committed Nov 21, 2024
1 parent 522c135 commit 7684a10
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions includes/Tasks/FsckTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ public function gh_fsck_file($path, $filename, $file_type, $source, $share, $sto
}
} else {
if ($source == 'metastore') {
SambaSpool::parse_samba_spool();
$query = "SELECT * FROM tasks WHERE action = 'rename' AND share = :share AND full_path = :full_path";
$task = DB::getFirst($query, array('share' => $share, 'full_path' => "$file_path/$filename"));
if ($task) {
Log::debug(" Missing symlink in LZ for $share/$file_path/$filename, but is OK because this file was renamed after fsck started.");
return;
}

if ($file_type == 'link' && !file_exists(readlink("$path/$filename"))) {
// Link points to now gone copy; let's just remove it, and treat this as if the link was not there in the first place.
unlink("$path/$filename");
Expand Down Expand Up @@ -592,6 +600,17 @@ public function gh_fsck_file($path, $filename, $file_type, $source, $share, $sto
}
}

if ($num_copies_required > 0 && $storage_path === FALSE && count($file_copies_inodes) == 0 && !isset($original_file_path)) {
// This could happen when scanning a file that was renamed after fsck started; the rename task will be executed afterward, so the file copies were not yet renamed, but the file or symlink (on the share's LZ) was already renamed
SambaSpool::parse_samba_spool();
$query = "SELECT * FROM tasks WHERE action = 'rename' AND share = :share AND additional_info = :full_path";
$task = DB::getFirst($query, array('share' => $share, 'full_path' => "$file_path/$filename"));
if ($task) {
Log::debug(" No file copies found, but is OK because this file was renamed after fsck started.");
return;
}
}

if (count($file_copies_inodes) == $num_copies_required) {
// It's okay if the file isn't a symlink so long as we're looking at a storage volume path and not a share path
/** @noinspection PhpUndefinedVariableInspection */
Expand Down

0 comments on commit 7684a10

Please sign in to comment.