Skip to content

Commit

Permalink
"file:" Location: use absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed Oct 14, 2024
1 parent 6adf18d commit ffdc958
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/borg/helpers/parseformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def _parse(self, text):
m = self.local_re.match(text)
if m:
self.proto = "file"
self.path = os.path.normpath(m.group("path"))
self.path = os.path.abspath(os.path.normpath(m.group("path")))
return True
return False

Expand Down
20 changes: 9 additions & 11 deletions src/borg/testsuite/helpers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,10 @@ def test_smb(self, monkeypatch, keys_dir):

def test_folder(self, monkeypatch, keys_dir):
monkeypatch.delenv("BORG_REPO", raising=False)
assert repr(Location("path")) == "Location(proto='file', user=None, host=None, port=None, path='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"]) + "_"
rel_path = "path"
abs_path = os.path.abspath(rel_path)
assert repr(Location(rel_path)) == f"Location(proto='file', user=None, host=None, port=None, path='{abs_path}')"
assert Location("path").to_key_filename().endswith(rel_path)

def test_abspath(self, monkeypatch, keys_dir):
monkeypatch.delenv("BORG_REPO", raising=False)
Expand All @@ -248,11 +246,11 @@ def test_abspath(self, monkeypatch, keys_dir):

def test_relpath(self, monkeypatch, keys_dir):
monkeypatch.delenv("BORG_REPO", raising=False)
assert (
repr(Location("relative/path"))
== "Location(proto='file', user=None, host=None, port=None, path='relative/path')"
)
assert Location("relative/path").to_key_filename() == keys_dir + "relative_path"
# for a local path, borg creates a Location instance with an absolute path
rel_path = "relative/path"
abs_path = os.path.abspath(rel_path)
assert repr(Location(rel_path)) == f"Location(proto='file', user=None, host=None, port=None, path='{abs_path}')"
assert Location(rel_path).to_key_filename().endswith("relative_path")
assert (
repr(Location("ssh://user@host/relative/path"))
== "Location(proto='ssh', user='user', host='host', port=None, path='relative/path')"
Expand Down

0 comments on commit ffdc958

Please sign in to comment.