Remove atomicwrites

Unfortunately the library doesn't support disabling of disk syncing, fortunately we only need a small subset of it's functionality which is easy to implement.
This commit is contained in:
Unrud 2016-08-08 05:02:36 +02:00
parent 3c736cade8
commit c336e0581e
2 changed files with 18 additions and 15 deletions

View File

@ -37,9 +37,8 @@ from hashlib import md5
from importlib import import_module from importlib import import_module
from itertools import groupby from itertools import groupby
from random import getrandbits from random import getrandbits
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory, NamedTemporaryFile
from atomicwrites import AtomicWriter
import vobject import vobject
@ -192,16 +191,6 @@ class EtagMismatchError(ValueError):
super().__init__(message) super().__init__(message)
class _EncodedAtomicWriter(AtomicWriter):
def __init__(self, path, encoding, mode="w", overwrite=True):
self._encoding = encoding
return super().__init__(path, mode, overwrite=True)
def get_fileobject(self, **kwargs):
return super().get_fileobject(
encoding=self._encoding, prefix=".Radicale.tmp-", **kwargs)
class Item: class Item:
def __init__(self, collection, item, href, last_modified=None): def __init__(self, collection, item, href, last_modified=None):
self.collection = collection self.collection = collection
@ -399,8 +388,22 @@ class Collection(BaseCollection):
@contextmanager @contextmanager
def _atomic_write(self, path, mode="w"): def _atomic_write(self, path, mode="w"):
with _EncodedAtomicWriter(path, self.encoding, mode).open() as fd: dir = os.path.dirname(path)
yield fd tmp = NamedTemporaryFile(mode=mode, dir=dir, encoding=self.encoding,
delete=False, prefix=".Radicale.tmp-")
try:
yield tmp
if os.name == "posix" and hasattr(fcntl, "F_FULLFSYNC"):
fcntl.fcntl(tmp.fileno(), fcntl.F_FULLFSYNC)
else:
os.fsync(tmp.fileno())
tmp.close()
os.rename(tmp.name, path)
except:
tmp.close()
os.remove(tmp.name)
raise
self._sync_directory(dir)
def _find_available_file_name(self): def _find_available_file_name(self):
# Prevent infinite loop # Prevent infinite loop

View File

@ -66,7 +66,7 @@ setup(
packages=["radicale"], packages=["radicale"],
provides=["radicale"], provides=["radicale"],
scripts=["bin/radicale"], scripts=["bin/radicale"],
install_requires=["vobject", "atomicwrites"], install_requires=["vobject"],
setup_requires=pytest_runner, setup_requires=pytest_runner,
tests_require=[ tests_require=[
"pytest-runner", "pytest-cov", "pytest-flake8", "pytest-isort"], "pytest-runner", "pytest-cov", "pytest-flake8", "pytest-isort"],