Browse Source

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

(cherry picked from commit 38ed9a20afe70b0becc473710a89d914ad5a2223)
Marian Beermann 8 years ago
parent
commit
1de042f9e5
2 changed files with 9 additions and 0 deletions
  1. 5 0
      borg/helpers.py
  2. 4 0
      borg/testsuite/helpers.py

+ 5 - 0
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):

+ 4 - 0
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')) == \