[PATCH v2 5/5] fsck: ensure all requested pack-*par2 files are not empty

0 views
Skip to first unread message

Rob Browning

unread,
Jun 19, 2024, 3:16:43 PM (14 days ago) Jun 19
to bup-...@googlegroups.com
Make sure all the relevant par2 files aren't empty. Previously, we
only checked whether the top-level PACK.idx index file was empty,
ignoring the vol files.

Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
lib/bup/cmd/fsck.py | 28 ++++++++++++++++++++++++----
note/0.33.x.md | 8 +++++---
2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/lib/bup/cmd/fsck.py b/lib/bup/cmd/fsck.py
index 1309543d2..fbec0f63e 100644
--- a/lib/bup/cmd/fsck.py
+++ b/lib/bup/cmd/fsck.py
@@ -9,9 +9,9 @@ import glob, os, subprocess, sys
from bup import options, git
from bup.compat import argv_bytes
from bup.helpers \
- import (EXIT_FALSE, EXIT_TRUE,
+ import (EXIT_FAILURE, EXIT_FALSE, EXIT_TRUE, EXIT_SUCCESS,
Sha1, chunkyreader, istty2, log, progress, temp_dir)
-from bup.io import byte_stream
+from bup.io import byte_stream, path_msg


par2_ok = 0
@@ -237,7 +237,7 @@ def main(argv):

sys.stdout.flush()
out = byte_stream(sys.stdout)
- code = 0
+ code = EXIT_SUCCESS
count = 0
outstanding = {}
for stem in pack_stems:
@@ -282,7 +282,27 @@ def main(argv):
count += 1
if not opt.verbose:
progress('fsck (%d/%d)\r' % (count, len(extra)))
-
if istty2:
debug('fsck done. \n')
+
+ for stem in pack_stems:
+ pack_dir, base = os.path.split(stem)
+ # Check par2 status. We look for empty *.par2 files because
+ # C-c during "par2 create" may produce them. For now, we
+ # decide the existing data is OK if the pack-HASH.par2 index
+ # file exists, and no pack-HASH*.par2 files are empty.
+ par2_idx = base + b'.par2'
+ par2_idx_ent, par2_found, par2_empty = None, False, False
+ for ent in [ent for ent in os.scandir(pack_dir)
+ if ent.name.startswith(base) and ent.name.endswith(b'.par2')]:
+ par2_found = True
+ if ent.name == par2_idx:
+ par2_idx_ent = ent
+ if ent.stat().st_size == 0:
+ log(f'error: empty file - {path_msg(ent.name)}\n')
+ par2_empty = True
+ if par2_found and (par2_empty or not par2_idx_ent):
+ if code == EXIT_SUCCESS:
+ code = EXIT_FAILURE
+
sys.exit(code)
diff --git a/note/0.33.x.md b/note/0.33.x.md
index 1fbd153fa..9401ee8db 100644
--- a/note/0.33.x.md
+++ b/note/0.33.x.md
@@ -7,8 +7,10 @@ May require attention
* The `par2` command (invoked by `bup fsck -g`) may generate empty
recovery files if interrupted (say via C-c). To mitigate this, bup
now runs `par2` in a temporary directory, and only moves the
- recovery files into place if the generation succeeds. See also
- https://github.com/Parchive/par2cmdline/issues/84
+ recovery files into place if the generation succeeds. It will also
+ look for any empty par2 files associated with packfiles that it has
+ been asked to examine. If found, they will provoke an error. See
+ also https://github.com/Parchive/par2cmdline/issues/84

* Previously, any `bup on REMOTE ...` commands that attempted to read
from standard input (for example `bup on HOST split < something` or
@@ -30,4 +32,4 @@ Bugs
Thanks to (at least)
====================

-...
+Greg Troxel, Johannes Berg, and ...
--
2.43.0

Reply all
Reply to author
Forward
0 new messages