mirror of
https://github.com/borgbackup/borg.git
synced 2026-06-11 01:41:57 -04:00
pathlib refactor platform.base
This commit is contained in:
parent
a0f73d7a61
commit
4ff49a6e91
1 changed files with 7 additions and 5 deletions
|
|
@ -2,6 +2,7 @@ import errno
|
|||
import os
|
||||
import socket
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
from ..helpers import safe_unlink
|
||||
from ..platformflags import is_win32
|
||||
|
|
@ -102,7 +103,7 @@ def sync_dir(path):
|
|||
# Opening directories is not supported on windows.
|
||||
# TODO: do we need to handle this in some other way?
|
||||
return
|
||||
fd = os.open(path, os.O_RDONLY)
|
||||
fd = os.open(str(path), os.O_RDONLY)
|
||||
try:
|
||||
os.fsync(fd)
|
||||
except OSError as os_error:
|
||||
|
|
@ -164,7 +165,7 @@ class SyncFile:
|
|||
mode = "xb" if binary else "x" # x -> raise FileExists exception in open() if file exists already
|
||||
self.path = path
|
||||
if fd is None:
|
||||
self.f = open(path, mode=mode) # python file object
|
||||
self.f = open(str(path), mode=mode) # python file object
|
||||
else:
|
||||
self.f = os.fdopen(fd, mode=mode)
|
||||
self.fd = self.f.fileno() # OS-level fd
|
||||
|
|
@ -197,7 +198,7 @@ class SyncFile:
|
|||
|
||||
dirname = None
|
||||
try:
|
||||
dirname = os.path.dirname(self.path)
|
||||
dirname = Path(self.path).parent
|
||||
self.sync()
|
||||
finally:
|
||||
self.f.close()
|
||||
|
|
@ -225,8 +226,9 @@ class SaveFile:
|
|||
def __init__(self, path, binary=False):
|
||||
self.binary = binary
|
||||
self.path = path
|
||||
self.dir = os.path.dirname(path)
|
||||
self.tmp_prefix = os.path.basename(path) + "-"
|
||||
path_obj = Path(path)
|
||||
self.dir = str(path_obj.parent)
|
||||
self.tmp_prefix = path_obj.name + "-"
|
||||
self.tmp_fd = None # OS-level fd
|
||||
self.tmp_fname = None # full path/filename corresponding to self.tmp_fd
|
||||
self.f = None # python-file-like SyncFile
|
||||
|
|
|
|||
Loading…
Reference in a new issue