From 839dd94a593691f6956f326185f60f2eae527ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Wed, 19 Mar 2014 21:58:25 +0100 Subject: [PATCH] prune: Delete all archives in a single transaction This will improve performance and make the whole operation atomic --- attic/archive.py | 5 +---- attic/archiver.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/attic/archive.py b/attic/archive.py index 50bc674dc..59acfdfed 100644 --- a/attic/archive.py +++ b/attic/archive.py @@ -316,7 +316,7 @@ class Archive: elif not symlink: os.utime(path, (item[b'mtime'] / 10**9, item[b'mtime'] / 10**9)) - def delete(self, cache): + def delete(self): unpacker = msgpack.Unpacker(use_list=False) for id_, data in zip(self.metadata[b'items'], self.repository.get_many(self.metadata[b'items'])): unpacker.feed(self.key.decrypt(id_, data)) @@ -328,9 +328,6 @@ class Archive: self.cache.chunk_decref(self.id) del self.manifest.archives[self.name] - self.manifest.write() - self.repository.commit() - cache.commit() def stat_attrs(self, st, path): item = { diff --git a/attic/archiver.py b/attic/archiver.py index 0293cdc65..20e4625cc 100644 --- a/attic/archiver.py +++ b/attic/archiver.py @@ -219,7 +219,10 @@ Type "Yes I am sure" if you understand this and want to continue.\n""") manifest, key = Manifest.load(repository) cache = Cache(repository, key, manifest) archive = Archive(repository, key, manifest, args.archive.archive, cache=cache) - archive.delete(cache) + archive.delete() + manifest.write() + repository.commit() + cache.commit() return self.exit_code def do_mount(self, args): @@ -338,7 +341,11 @@ Type "Yes I am sure" if you understand this and want to continue.\n""") self.print_verbose('Would prune: %s' % format_archive(archive)) else: self.print_verbose('Pruning archive: %s' % format_archive(archive)) - archive.delete(cache) + archive.delete() + if to_delete and not args.dry_run: + manifest.write() + repository.commit() + cache.commit() return self.exit_code helptext = {}