From 1de042f9e55b9204c66d67efb6e0498856e50625 Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Thu, 25 May 2017 12:36:45 +0200 Subject: [PATCH] key file names: limit to 100 characters (not bytes) (cherry picked from commit 38ed9a20afe70b0becc473710a89d914ad5a2223) --- borg/helpers.py | 5 +++++ borg/testsuite/helpers.py | 4 ++++ 2 files changed, 9 insertions(+) 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')) == \