-
-
Notifications
You must be signed in to change notification settings - Fork 836
Description
Hello,
I've just hit something strange (from the user's point of view) when adding functionality for a helper-script to using borg within backupninja. The feature I was adding was the possibility of displacing the cache dir. For this I set the BORG_CACHE_DIR env var to what users set in the configuration file.
Now the issue that happened was that if somehow the variable BORG_CACHE_DIR ends up empty (and exported as such to the environment), borg uses this empty string as the path to the cache dir and obviously fails, which is confusing for users:
$ export BORG_CACHE_DIR=
$ borg create ./testborg::blah somesourcedir
Local Exception
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/borg/archiver.py", line 4529, in main
exit_code = archiver.run(args)
File "/usr/lib/python3/dist-packages/borg/archiver.py", line 4461, in run
return set_ec(func(args))
File "/usr/lib/python3/dist-packages/borg/archiver.py", line 157, in wrapper
assert_secure(repository, kwargs['manifest'], self.lock_wait)
File "/usr/lib/python3/dist-packages/borg/cache.py", line 205, in assert_secure
sm = SecurityManager(repository)
File "/usr/lib/python3/dist-packages/borg/cache.py", line 63, in __init__
self.cache_dir = cache_dir(repository)
File "/usr/lib/python3/dist-packages/borg/cache.py", line 226, in cache_dir
return path or os.path.join(get_cache_dir(), repository.id_str)
File "/usr/lib/python3/dist-packages/borg/helpers.py", line 553, in get_cache_dir
os.makedirs(cache_dir)
File "/usr/lib/python3.8/os.py", line 223, in makedirs
mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: ''
Platform: Linux meevyl 5.6.0-1-amd64 #1 SMP Debian 5.6.7-1 (2020-04-29) x86_64
Linux: Unknown Linux
Borg: 1.1.11 Python: CPython 3.8.3 msgpack: 0.5.6
PID: 990872 CWD: /home/gabster/dev
sys.argv: ['/usr/bin/borg', 'create', './testborg::blah', 'backupninja']
SSH_ORIGINAL_COMMAND: None
If the env var BORG_CACHE_DIR exists, I would argue that borg should probably add a check to make sure that it is non-empty. if it is, then it should be discarded and the default cache dir placement should be used.
Bounty: https://www.bountysource.com/issues/91660210-setting-borg_cache_dir-to-an-empty-string-crashes-borg