From 62469d097b13862be6fd8f930b93a09fc24547cb Mon Sep 17 00:00:00 2001 From: Andrea Lazzarotto Date: Mon, 21 Aug 2017 19:03:18 +0200 Subject: [PATCH] Restore and rebuild should not break after a merge. Fix #20 --- main.py | 19 +++++++++++-------- recuperabit/fs/core_types.py | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 3184b35..bd933f3 100755 --- a/main.py +++ b/main.py @@ -212,14 +212,17 @@ def interpret(cmd, arguments, parts, shorthands, outdir): return print 'Merging partitions...' utils.merge(part1, part2) - position = int(arguments[1]) - _, par = shorthands[position] - del shorthands[position] - del parts[par] - try: - rebuilt.remove(par) - except: - pass + source_position = int(arguments[1]) + destination_position = int(arguments[0]) + _, par_source = shorthands[source_position] + _, par_destination = shorthands[destination_position] + del shorthands[source_position] + del parts[par_source] + for par in (par_source, par_destination): + try: + rebuilt.remove(par) + except: + pass print 'There are now %d partitions.' % (len(parts), ) elif cmd == 'recoverable': list_parts(parts, shorthands, lambda x: x.recoverable) diff --git a/recuperabit/fs/core_types.py b/recuperabit/fs/core_types.py index 3ba925a..907fa08 100644 --- a/recuperabit/fs/core_types.py +++ b/recuperabit/fs/core_types.py @@ -77,6 +77,9 @@ def add_child(self, node): """Add a new child to this directory.""" original_name = node.name i = 0 + # Check for multiple rebuilds + if node in self.children: + return # Avoid name clashes while node.name in self.children_names: node.name = original_name + '_%03d' % i