diff --git a/borg/helpers.py b/borg/helpers.py index 6f933d7ab..e5f9fbd77 100644 --- a/borg/helpers.py +++ b/borg/helpers.py @@ -1086,6 +1086,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): diff --git a/borg/testsuite/helpers.py b/borg/testsuite/helpers.py index 104eb74e5..b63ff6f3e 100644 --- a/borg/testsuite/helpers.py +++ b/borg/testsuite/helpers.py @@ -125,6 +125,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')) == \