Skip to content

Commit

Permalink
BUG Fix jug cleanup when packs are used
Browse files Browse the repository at this point in the history
  • Loading branch information
luispedro committed Jul 18, 2022
1 parent ffe3710 commit c2eea11
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
10 changes: 6 additions & 4 deletions jug/backends/file_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,18 @@ def cleanup(self, active, keeplocks=False):
active = frozenset(t.hash() for t in active)
active_fnames = frozenset(self._getfname(h) for h in active)
removed = 0
for dir,_,fs in os.walk(self.jugdir):
if keeplocks and dir == "locks":
for dirpath,_,fs in os.walk(self.jugdir):
if keeplocks and path.basename(dirpath) == "locks":
continue
if path.basename(dirpath) == "packs":
continue
for f in fs:
f = path.join(dir, f)
f = path.join(dirpath, f)
if f not in active_fnames:
os.unlink(f)
removed += 1
pack_dirty = False
for k in frozenset(self.packed.keys()) & active:
for k in frozenset(self.packed.keys()) - active:
del self.packed[k]
pack_dirty = True
removed += 1
Expand Down
32 changes: 32 additions & 0 deletions jug/tests/test_file_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,35 @@ def assert_contains_data(st, data):
fs = file_store(tmpdir)
assert_contains_data(fs, data)
fs.close()

class MockHash:
def __init__(self, h):
self.h = h

def hash(self):
return self.h

def test_pack_cleanup(tmpdir):
tmpdir = str(tmpdir)
fs = file_store(tmpdir)
assert len(list(fs.listlocks())) == 0
key1 = b'jugisbestthingever'
key2 = b'jug_key2'
ob1 = [1]
ob2 = [1, 2]
fs.dump(ob1, key1)
fs.dump(ob2, key2)

assert len(list(fs.list())) == 2
assert fs.cleanup([MockHash(key1), MockHash(key2)], keeplocks=False) == 0

assert len(list(fs.list())) == 2
packed = fs.update_pack()
assert packed == 2
assert fs.cleanup([MockHash(key1), MockHash(key2)], keeplocks=False) == 0
assert len(list(fs.list())) == 2

fs.close()

fs = file_store(tmpdir)
assert len(list(fs.list())) == 2

0 comments on commit c2eea11

Please sign in to comment.