sisi update's backup survives git housekeeping removing a lock file while the data folder is copied (found by the repeat runs). done / next: repeat runs, report
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4180df8544
commit
a245d32065
2 files changed
+32
-1
No files matched your search
+7
-1
@@ -38,7 +38,13 @@ def _copy_into(src, bdir, rel):
|
|||||||
dst = os.path.join(bdir, rel)
|
dst = os.path.join(bdir, rel)
|
||||||
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||||
if os.path.isdir(src):
|
if os.path.isdir(src):
|
||||||
shutil.copytree(src, dst, dirs_exist_ok=True)
|
try:
|
||||||
|
# lock files are not data, and git's background maintenance removes them while we copy
|
||||||
|
shutil.copytree(src, dst, dirs_exist_ok=True, ignore=shutil.ignore_patterns("*.lock", "gc.pid"))
|
||||||
|
except shutil.Error as e:
|
||||||
|
# a file that vanished while being copied (git housekeeping in the personal repository) is not a failure
|
||||||
|
if not all(isinstance(x, tuple) and "No such file or directory" in str(x[2]) for x in e.args[0]):
|
||||||
|
raise
|
||||||
elif src.endswith(".db"):
|
elif src.endswith(".db"):
|
||||||
_sqlite_copy(src, dst)
|
_sqlite_copy(src, dst)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -949,3 +949,28 @@ class Odds(Base):
|
|||||||
text = self.sisi("cycle").stdout
|
text = self.sisi("cycle").stdout
|
||||||
self.assertLessEqual(len(text), 6000)
|
self.assertLessEqual(len(text), 6000)
|
||||||
self.assertEqual(text.count("FLAGGED NOT WORKING"), 8)
|
self.assertEqual(text.count("FLAGGED NOT WORKING"), 8)
|
||||||
|
|
||||||
|
|
||||||
|
class Snapshot(Base):
|
||||||
|
"""R-16-9 (item 4's repair runs inside `sisi update`, whose backup must not fail on git housekeeping)."""
|
||||||
|
|
||||||
|
def test_a_file_that_vanishes_while_the_backup_copies_the_data_folder_is_not_a_failure(self):
|
||||||
|
import shutil, unittest.mock
|
||||||
|
from sisi import lifecycle
|
||||||
|
d = os.path.join(self.tmp, "src")
|
||||||
|
os.makedirs(os.path.join(d, "objects"))
|
||||||
|
for n in ("a", "b"):
|
||||||
|
with open(os.path.join(d, n), "w") as f:
|
||||||
|
f.write(n)
|
||||||
|
with open(os.path.join(d, "objects", "maintenance.lock"), "w") as f:
|
||||||
|
f.write("x")
|
||||||
|
real = shutil.copy2
|
||||||
|
|
||||||
|
def vanishing(src, dst, **kw):
|
||||||
|
if os.path.basename(src) == "b":
|
||||||
|
os.unlink(src) # removed by another process between listing and copying
|
||||||
|
return real(src, dst, **kw)
|
||||||
|
with unittest.mock.patch("shutil.copy2", vanishing):
|
||||||
|
lifecycle._copy_into(d, os.path.join(self.tmp, "bak"), "src")
|
||||||
|
self.assertTrue(os.path.exists(os.path.join(self.tmp, "bak", "src", "a")))
|
||||||
|
self.assertFalse(os.path.exists(os.path.join(self.tmp, "bak", "src", "objects", "maintenance.lock")))
|
||||||
Reference in new issue
Block a user