key file names: limit to 100 characters (not bytes)

This commit is contained in:
Marian Beermann 2017-05-25 12:36:45 +02:00
parent 4b8a04b5e7
commit 38ed9a20af
2 changed files with 9 additions and 0 deletions

View file

@ -917,6 +917,11 @@ class Location:
name = re.sub('[^\w]', '_', self.path).strip('_')
if self.proto != 'file':
name = re.sub('[^\w]', '_', self.host) + '__' + name
if len(name) > 100:
# Limit file names to some reasonable length. Most file systems
# limit them to 255 [unit of choice]; due to variations in unicode
# handling we truncate to 100 *characters*.
name = name[:100]
return os.path.join(get_keys_dir(), name)
def __repr__(self):

View file

@ -141,6 +141,10 @@ class TestLocationWithoutEnv:
"Location(proto='file', user=None, host=None, port=None, path='path', archive=None)"
assert Location('path').to_key_filename() == keys_dir + 'path'
def test_long_path(self, monkeypatch, keys_dir):
monkeypatch.delenv('BORG_REPO', raising=False)
assert Location(os.path.join(*(40 * ['path']))).to_key_filename() == keys_dir + '_'.join(20 * ['path']) + '_'
def test_abspath(self, monkeypatch, keys_dir):
monkeypatch.delenv('BORG_REPO', raising=False)
assert repr(Location('/some/absolute/path::archive')) == \