Skip to content

Commit ff8c704

Browse files
committed
file url fixes
1 parent 1373b30 commit ff8c704

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

src/borg/legacyrepository.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import stat
66
import struct
77
import time
8+
from pathlib import Path
89
from collections import defaultdict
910
from configparser import ConfigParser
1011
from functools import partial
@@ -190,8 +191,9 @@ class PathPermissionDenied(Error):
190191
exit_mcode = 21
191192

192193
def __init__(self, path, create=False, exclusive=False, lock_wait=None, lock=True, send_log_cb=None):
193-
self.path = os.path.abspath(path)
194-
self._location = Location("file://%s" % self.path)
194+
p = Path(path).absolute()
195+
self.path = str(p)
196+
self._location = Location(p.as_uri())
195197
self.version = None
196198
# long-running repository methods which emit log or progress output are responsible for calling
197199
# the ._send_log method periodically to get log and progress output transferred to the borg client

src/borg/repository.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
2-
import sys
32
import time
3+
from pathlib import Path
44

55
from borgstore.store import Store
66
from borgstore.store import ObjectNotFound as StoreObjectNotFound
@@ -106,11 +106,11 @@ def __init__(
106106
if isinstance(path_or_location, Location):
107107
location = path_or_location
108108
if location.proto == "file":
109-
url = _local_abspath_to_file_url(location.path) # frequently users give without file:// prefix
109+
url = Path(location.path).as_uri() # frequently users give without file:// prefix
110110
else:
111111
url = location.processed # location as given by user, processed placeholders
112112
else:
113-
url = _local_abspath_to_file_url(os.path.abspath(path_or_location))
113+
url = Path(path_or_location).absolute().as_uri()
114114
location = Location(url)
115115
self._location = location
116116
self.url = url
@@ -566,16 +566,3 @@ def store_delete(self, name, *, deleted=False):
566566
def store_move(self, name, new_name=None, *, delete=False, undelete=False, deleted=False):
567567
self._lock_refresh()
568568
return self.store.move(name, new_name, delete=delete, undelete=undelete, deleted=deleted)
569-
570-
571-
def _local_abspath_to_file_url(path: str) -> str:
572-
"""Create a file URL from a local, absolute path.
573-
574-
Expects `path` to be an absolute path on the local filesystem, e.g.:
575-
- POSIX: `/foo/bar`
576-
- Windows: `c:/foo/bar` (or `c:\foo\bar`)
577-
The easiest way to ensure this is for the caller to pass `path` through `os.path.abspath` first.
578-
"""
579-
if sys.platform in ("win32", "msys", "cygwin"):
580-
path = "/" + path.replace("\\", "/")
581-
return "file://%s" % path

src/borg/testsuite/archiver/lock_cmds_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import subprocess
33
import time
4+
from pathlib import Path
45

56
from ...constants import * # NOQA
67
from . import cmd, generate_archiver_tests, RK_ENCRYPTION
@@ -18,7 +19,7 @@ def test_break_lock(archivers, request):
1819
def test_with_lock(tmp_path):
1920
repo_path = tmp_path / "repo"
2021
env = os.environ.copy()
21-
env["BORG_REPO"] = "file://" + str(repo_path)
22+
env["BORG_REPO"] = Path(repo_path).as_uri()
2223
command0 = "python3", "-m", "borg", "repo-create", "--encryption=none"
2324
# Timings must be adjusted so that command1 keeps running while command2 tries to get the lock,
2425
# so that lock acquisition for command2 fails as the test expects it.

src/borg/testsuite/storelocking_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
from pathlib import Path
23

34
import pytest
45

@@ -12,7 +13,7 @@
1213

1314
@pytest.fixture()
1415
def lockstore(tmpdir):
15-
store = Store("file://" + str(tmpdir / "lockstore"), levels={"locks/": [0]})
16+
store = Store(Path(tmpdir / "lockstore").as_uri(), levels={"locks/": [0]})
1617
store.create()
1718
with store:
1819
yield store

0 commit comments

Comments
 (0)