mirror of https://github.com/borgbackup/borg.git
fix borg config --cache (make sure cache gets closed via try/finally)
(cherry picked from commit 322b442641
)
This commit is contained in:
parent
0405c1a1bb
commit
6783894ff3
|
@ -1578,38 +1578,39 @@ class Archiver:
|
||||||
assert_secure(repository, manifest)
|
assert_secure(repository, manifest)
|
||||||
cache = Cache(repository, key, manifest, lock_wait=self.lock_wait)
|
cache = Cache(repository, key, manifest, lock_wait=self.lock_wait)
|
||||||
|
|
||||||
if args.cache:
|
try:
|
||||||
cache.cache_config.load()
|
if args.cache:
|
||||||
config = cache.cache_config._config
|
cache.cache_config.load()
|
||||||
save = cache.cache_config.save
|
config = cache.cache_config._config
|
||||||
validate = cache_validate
|
save = cache.cache_config.save
|
||||||
else:
|
validate = cache_validate
|
||||||
config = repository.config
|
else:
|
||||||
save = lambda: repository.save_config(repository.path, repository.config)
|
config = repository.config
|
||||||
validate = repo_validate
|
save = lambda: repository.save_config(repository.path, repository.config)
|
||||||
|
validate = repo_validate
|
||||||
|
|
||||||
if args.delete:
|
if args.delete:
|
||||||
validate(section, name, check_value=False)
|
validate(section, name, check_value=False)
|
||||||
config.remove_option(section, name)
|
config.remove_option(section, name)
|
||||||
if len(config.options(section)) == 0:
|
if len(config.options(section)) == 0:
|
||||||
config.remove_section(section)
|
config.remove_section(section)
|
||||||
save()
|
save()
|
||||||
elif args.value:
|
elif args.value:
|
||||||
validate(section, name, args.value)
|
validate(section, name, args.value)
|
||||||
if section not in config.sections():
|
if section not in config.sections():
|
||||||
config.add_section(section)
|
config.add_section(section)
|
||||||
config.set(section, name, args.value)
|
config.set(section, name, args.value)
|
||||||
save()
|
save()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
print(config.get(section, name))
|
print(config.get(section, name))
|
||||||
except (configparser.NoOptionError, configparser.NoSectionError) as e:
|
except (configparser.NoOptionError, configparser.NoSectionError) as e:
|
||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
return EXIT_WARNING
|
return EXIT_WARNING
|
||||||
|
return EXIT_SUCCESS
|
||||||
if args.cache:
|
finally:
|
||||||
cache.close()
|
if args.cache:
|
||||||
return EXIT_SUCCESS
|
cache.close()
|
||||||
|
|
||||||
def do_debug_info(self, args):
|
def do_debug_info(self, args):
|
||||||
"""display system information for debugging / bug reports"""
|
"""display system information for debugging / bug reports"""
|
||||||
|
|
Loading…
Reference in New Issue