1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-01-30 19:21:17 +00:00

borg delete: fix --cache-only for broken caches

This also makes --cache-only idempotent: it won't fail if the cache
is already deleted.

Fixes #874
This commit is contained in:
Marian Beermann 2016-04-11 12:50:39 +02:00
parent 8dbbc35b71
commit d12c1deece
No known key found for this signature in database
GPG key ID: 9B8450B91D1362C1
2 changed files with 25 additions and 22 deletions

View file

@ -396,22 +396,23 @@ def do_rename(self, args, repository, manifest, key, cache, archive):
cache.commit()
return self.exit_code
@with_repository(exclusive=True, cache=True)
def do_delete(self, args, repository, manifest, key, cache):
@with_repository(exclusive=True)
def do_delete(self, args, repository, manifest, key):
"""Delete an existing repository or archive"""
if args.location.archive:
archive = Archive(repository, key, manifest, args.location.archive, cache=cache)
stats = Statistics()
archive.delete(stats, progress=args.progress)
manifest.write()
repository.commit(save_space=args.save_space)
cache.commit()
logger.info("Archive deleted.")
if args.stats:
log_multi(DASHES,
stats.summary.format(label='Deleted data:', stats=stats),
str(cache),
DASHES)
with Cache(repository, key, manifest, lock_wait=self.lock_wait) as cache:
archive = Archive(repository, key, manifest, args.location.archive, cache=cache)
stats = Statistics()
archive.delete(stats, progress=args.progress)
manifest.write()
repository.commit(save_space=args.save_space)
cache.commit()
logger.info("Archive deleted.")
if args.stats:
log_multi(DASHES,
stats.summary.format(label='Deleted data:', stats=stats),
str(cache),
DASHES)
else:
if not args.cache_only:
msg = []
@ -426,7 +427,7 @@ def do_delete(self, args, repository, manifest, key, cache):
return self.exit_code
repository.destroy()
logger.info("Repository deleted.")
cache.destroy()
Cache.destroy(repository)
logger.info("Cache deleted.")
return self.exit_code

View file

@ -37,6 +37,15 @@ def break_lock(repository, path=None):
path = path or os.path.join(get_cache_dir(), hexlify(repository.id).decode('ascii'))
UpgradableLock(os.path.join(path, 'lock'), exclusive=True).break_lock()
@staticmethod
def destroy(repository, path=None):
"""destroy the cache for ``repository`` or at ``path``"""
path = path or os.path.join(get_cache_dir(), hexlify(repository.id).decode('ascii'))
config = os.path.join(path, 'config')
if os.path.exists(config):
os.remove(config) # kill config first
shutil.rmtree(path)
def __init__(self, repository, key, manifest, path=None, sync=True, do_files=False, warn_if_unencrypted=True,
lock_wait=None):
self.lock = None
@ -120,13 +129,6 @@ def create(self):
with open(os.path.join(self.path, 'files'), 'wb') as fd:
pass # empty file
def destroy(self):
"""destroy the cache at `self.path`
"""
self.close()
os.remove(os.path.join(self.path, 'config')) # kill config first
shutil.rmtree(self.path)
def _do_open(self):
self.config = configparser.ConfigParser(interpolation=None)
config_path = os.path.join(self.path, 'config')