Skip to content

Commit 4492810

Browse files
committed
will_delete factored back in to AptBtrfsSnapshot.delete()
It is a messy solution, but it works and I can't be bothered to change it yet.
1 parent b9cab9d commit 4492810

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

TODO

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Roadmap in order of planned implementation
22

3-
question: what happens if mounting fails
3+
refactor will_delete back into apt_btrfs_snapshot delete()
44

55
put on launchpad and publicise

apt_btrfs_snapshot.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,32 @@ def delete(self, snapshot):
362362
snapshot.name.startswith(SNAP_PREFIX)):
363363

364364
# correct parent links and combine change info
365-
snapshot.will_delete()
365+
parent = snapshot.parent
366+
children = snapshot.children
367+
old_history = snapshot.changes
368+
369+
# clean-ups in the global vars of
370+
snapshots.list_of.remove(snapshot)
371+
if parent != None and parent.name in snapshots.children:
372+
snapshots.children[parent.name].remove(snapshot)
373+
374+
for child in children:
375+
child.parent = parent
376+
377+
# and do the same again in the global vars of snapshots
378+
# messy but necessary for delete_older_than to work
379+
snapshots.parents[child.name] = parent
380+
if parent != None:
381+
snapshots.children[parent.name].append(child) # necessary
382+
383+
newer_history = child.changes
384+
if old_history == None:
385+
combined = newer_history
386+
elif newer_history == None:
387+
combined = None
388+
else:
389+
combined = old_history + newer_history
390+
child.changes = combined
366391

367392
res = self.commands.btrfs_delete_snapshot(to_delete)
368393
else:

snapshots.py

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def _set_parent(self, parent):
182182
""" sets symlink from child to parent
183183
or deletes it if parent == None
184184
"""
185+
old_parent = self.parent
185186
parent_file = os.path.join(mp, self.name, PARENT_LINK)
186187
# remove parent link from self
187188
if os.path.lexists(parent_file):

test/test_snapshots.py

+7-20
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@ def test_parse_orphans(self):
6666
self.assertEqual(len(snapshots.orphans), 3)
6767

6868
def test_set_parent(self):
69-
child = SNAP_PREFIX + "2013-07-31_12:53:16-raring-to-go"
70-
Snapshot(child).parent = None
69+
child = Snapshot(SNAP_PREFIX + "2013-07-31_12:53:16-raring-to-go")
70+
old_parent = child.parent
71+
child.parent = None
7172
parent_file = os.path.join(self.sandbox,
7273
SNAP_PREFIX + "2013-07-31_12:53:16-raring-to-go", PARENT_LINK)
7374
self.assertFalse(os.path.exists(parent_file))
74-
Snapshot(child).parent = SNAP_PREFIX + "2013-07-26_14:50:53"
75+
76+
new_parent = SNAP_PREFIX + "2013-07-26_14:50:53"
77+
child.parent = new_parent
7578
self.assertEqual(os.readlink(parent_file),
76-
os.path.join(PARENT_DOTS, SNAP_PREFIX + "2013-07-26_14:50:53"))
79+
os.path.join(PARENT_DOTS, new_parent))
7780

7881
def test_list_snapshots(self):
7982
res = [s.name for s in snapshots.get_list()]
@@ -124,22 +127,6 @@ def test_tag(self):
124127
self.assertEqual(tagged.tag, "raring-to-go")
125128
self.assertEqual(not_tagged.tag, "")
126129

127-
def test_will_delete(self):
128-
list_of = snapshots.list_of
129-
random.shuffle(list_of)
130-
for snap in list_of:
131-
parent = snap.parent
132-
children = snap.children
133-
snap.will_delete()
134-
self.assertNotIn(snap, snapshots.list_of)
135-
self.assertNotIn(snap.name, snapshots.parents)
136-
self.assertNotIn(snap.name, snapshots.children)
137-
for child in children:
138-
self.assertEqual(child.parent, parent)
139-
if parent != None:
140-
self.assertIn(child, parent.children)
141-
snapshots.setup(self.sandbox)
142-
143130

144131
if __name__ == "__main__":
145132
unittest.main()

0 commit comments

Comments
 (0)