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

(cherry picked from commit 38ed9a20af)
This commit is contained in:
Marian Beermann 2017-05-25 12:36:45 +02:00 committed by Thomas Waldmann
parent 649afe0c17
commit 1de042f9e5
2 changed files with 9 additions and 0 deletions

View File

@ -1086,6 +1086,11 @@ class Location:
name = re.sub('[^\w]', '_', self.path).strip('_') name = re.sub('[^\w]', '_', self.path).strip('_')
if self.proto != 'file': if self.proto != 'file':
name = re.sub('[^\w]', '_', self.host) + '__' + name 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) return os.path.join(get_keys_dir(), name)
def __repr__(self): def __repr__(self):

View File

@ -125,6 +125,10 @@ class TestLocationWithoutEnv:
"Location(proto='file', user=None, host=None, port=None, path='path', archive=None)" "Location(proto='file', user=None, host=None, port=None, path='path', archive=None)"
assert Location('path').to_key_filename() == keys_dir + 'path' 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): def test_abspath(self, monkeypatch, keys_dir):
monkeypatch.delenv('BORG_REPO', raising=False) monkeypatch.delenv('BORG_REPO', raising=False)
assert repr(Location('/some/absolute/path::archive')) == \ assert repr(Location('/some/absolute/path::archive')) == \