From ffdc9581d99b2d456686481c59182857e5e5ac4d Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 15 Oct 2024 01:21:41 +0200 Subject: [PATCH] "file:" Location: use absolute path --- src/borg/helpers/parseformat.py | 2 +- src/borg/testsuite/helpers_test.py | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/borg/helpers/parseformat.py b/src/borg/helpers/parseformat.py index c940527323..f995c84670 100644 --- a/src/borg/helpers/parseformat.py +++ b/src/borg/helpers/parseformat.py @@ -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 diff --git a/src/borg/testsuite/helpers_test.py b/src/borg/testsuite/helpers_test.py index d0ca464a71..102ead54b5 100644 --- a/src/borg/testsuite/helpers_test.py +++ b/src/borg/testsuite/helpers_test.py @@ -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) @@ -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')"