Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/borg/legacyrepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import stat
import struct
import time
from pathlib import Path
from collections import defaultdict
from configparser import ConfigParser
from functools import partial
Expand Down Expand Up @@ -190,8 +191,9 @@ class PathPermissionDenied(Error):
exit_mcode = 21

def __init__(self, path, create=False, exclusive=False, lock_wait=None, lock=True, send_log_cb=None):
self.path = os.path.abspath(path)
self._location = Location("file://%s" % self.path)
p = Path(path).absolute()
self.path = str(p)
self._location = Location(p.as_uri())
self.version = None
# long-running repository methods which emit log or progress output are responsible for calling
# the ._send_log method periodically to get log and progress output transferred to the borg client
Expand Down
19 changes: 3 additions & 16 deletions src/borg/repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
import time
from pathlib import Path

from borgstore.store import Store
from borgstore.store import ObjectNotFound as StoreObjectNotFound
Expand Down Expand Up @@ -106,11 +106,11 @@ def __init__(
if isinstance(path_or_location, Location):
location = path_or_location
if location.proto == "file":
url = _local_abspath_to_file_url(location.path) # frequently users give without file:// prefix
url = Path(location.path).as_uri() # frequently users give without file:// prefix
else:
url = location.processed # location as given by user, processed placeholders
else:
url = _local_abspath_to_file_url(os.path.abspath(path_or_location))
url = Path(path_or_location).absolute().as_uri()
location = Location(url)
self._location = location
self.url = url
Expand Down Expand Up @@ -566,16 +566,3 @@ def store_delete(self, name, *, deleted=False):
def store_move(self, name, new_name=None, *, delete=False, undelete=False, deleted=False):
self._lock_refresh()
return self.store.move(name, new_name, delete=delete, undelete=undelete, deleted=deleted)


def _local_abspath_to_file_url(path: str) -> str:
"""Create a file URL from a local, absolute path.

Expects `path` to be an absolute path on the local filesystem, e.g.:
- POSIX: `/foo/bar`
- Windows: `c:/foo/bar` (or `c:\foo\bar`)
The easiest way to ensure this is for the caller to pass `path` through `os.path.abspath` first.
"""
if sys.platform in ("win32", "msys", "cygwin"):
path = "/" + path.replace("\\", "/")
return "file://%s" % path
3 changes: 2 additions & 1 deletion src/borg/testsuite/archiver/lock_cmds_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import subprocess
import time
from pathlib import Path

from ...constants import * # NOQA
from . import cmd, generate_archiver_tests, RK_ENCRYPTION
Expand All @@ -18,7 +19,7 @@ def test_break_lock(archivers, request):
def test_with_lock(tmp_path):
repo_path = tmp_path / "repo"
env = os.environ.copy()
env["BORG_REPO"] = "file://" + str(repo_path)
env["BORG_REPO"] = Path(repo_path).as_uri()
command0 = "python3", "-m", "borg", "repo-create", "--encryption=none"
# Timings must be adjusted so that command1 keeps running while command2 tries to get the lock,
# so that lock acquisition for command2 fails as the test expects it.
Expand Down
3 changes: 2 additions & 1 deletion src/borg/testsuite/storelocking_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from pathlib import Path

import pytest

Expand All @@ -12,7 +13,7 @@

@pytest.fixture()
def lockstore(tmpdir):
store = Store("file://" + str(tmpdir / "lockstore"), levels={"locks/": [0]})
store = Store(Path(tmpdir / "lockstore").as_uri(), levels={"locks/": [0]})
store.create()
with store:
yield store
Expand Down
Loading