diff --git a/secondary.py b/secondary.py index f95e01f8a91d230dd9f86a1c5748be4d6969cda6..6a1f038d636a999f49396977c2c9774d7be25d01 100644 --- a/secondary.py +++ b/secondary.py @@ -48,19 +48,20 @@ class Backup: def __init__(self, primary_tar, mount, path, status, log): self.primary_tar = primary_tar self.primary_in = primary_tar.makefile('wb') + # Make sure that the generated tar archive is not empty + self.primary_in.write(b'.\0') self.primary_out = primary_tar.makefile('rb') self.mount = mount self.path = path self.status = status self.log = log + self.last_parent = b'' self.dst_root = os.path.join(mount, path).encode('utf-8') self.trash_root = os.path.join(mount, 'TRASH').encode('utf-8') self.trash = os.path.join(self.trash_root, str(int(time.time())).encode('utf-8')) self.extractor = threading.Thread(daemon=True, target=self.run) self.extractor.start() - # Make sure that the generated tar archive is not empty - self.primary_in.write(b'.\0') pass def run(self): @@ -128,17 +129,30 @@ class Backup: else: self.log.MESSAGE('Removing file', d) os.unlink(d) + pass + pass + pass - def add(self, src): - self.log.DEBUG('Add:', src.name) + def add_parents(self, src): + last_parent = self.last_parent parent = os.path.dirname(src.name) + self.last_parent = parent while len(parent) != 0: # Make sure directories get the correct modes + if last_parent.startswith(parent): + print('Break at:', parent, file=sys.stderr) + break print('Parent:', parent, file=sys.stderr) self.primary_in.write(parent + b'\0') + self.primary_in.flush() parent = os.path.dirname(parent) pass + pass + + def add(self, src): + self.log.DEBUG('Add:', src.name) print('File:', src.name, file=sys.stderr) + self.add_parents(src) self.primary_in.write(src.name + b'\0') self.primary_in.flush()