|
@@ -2,6 +2,7 @@ import errno
|
|
import os
|
|
import os
|
|
import socket
|
|
import socket
|
|
import uuid
|
|
import uuid
|
|
|
|
+from pathlib import Path
|
|
|
|
|
|
from ..helpers import safe_unlink
|
|
from ..helpers import safe_unlink
|
|
from ..platformflags import is_win32
|
|
from ..platformflags import is_win32
|
|
@@ -102,7 +103,7 @@ def sync_dir(path):
|
|
# Opening directories is not supported on windows.
|
|
# Opening directories is not supported on windows.
|
|
# TODO: do we need to handle this in some other way?
|
|
# TODO: do we need to handle this in some other way?
|
|
return
|
|
return
|
|
- fd = os.open(path, os.O_RDONLY)
|
|
|
|
|
|
+ fd = os.open(str(path), os.O_RDONLY)
|
|
try:
|
|
try:
|
|
os.fsync(fd)
|
|
os.fsync(fd)
|
|
except OSError as os_error:
|
|
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
|
|
mode = "xb" if binary else "x" # x -> raise FileExists exception in open() if file exists already
|
|
self.path = path
|
|
self.path = path
|
|
if fd is None:
|
|
if fd is None:
|
|
- self.f = open(path, mode=mode) # python file object
|
|
|
|
|
|
+ self.f = open(str(path), mode=mode) # python file object
|
|
else:
|
|
else:
|
|
self.f = os.fdopen(fd, mode=mode)
|
|
self.f = os.fdopen(fd, mode=mode)
|
|
self.fd = self.f.fileno() # OS-level fd
|
|
self.fd = self.f.fileno() # OS-level fd
|
|
@@ -197,7 +198,7 @@ class SyncFile:
|
|
|
|
|
|
dirname = None
|
|
dirname = None
|
|
try:
|
|
try:
|
|
- dirname = os.path.dirname(self.path)
|
|
|
|
|
|
+ dirname = Path(self.path).parent
|
|
self.sync()
|
|
self.sync()
|
|
finally:
|
|
finally:
|
|
self.f.close()
|
|
self.f.close()
|
|
@@ -225,8 +226,9 @@ class SaveFile:
|
|
def __init__(self, path, binary=False):
|
|
def __init__(self, path, binary=False):
|
|
self.binary = binary
|
|
self.binary = binary
|
|
self.path = path
|
|
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_fd = None # OS-level fd
|
|
self.tmp_fname = None # full path/filename corresponding to self.tmp_fd
|
|
self.tmp_fname = None # full path/filename corresponding to self.tmp_fd
|
|
self.f = None # python-file-like SyncFile
|
|
self.f = None # python-file-like SyncFile
|