Merge pull request #478 from Unrud/patch-33
Correctly write line endings to files
This commit is contained in:
commit
f395e256ff
@ -391,11 +391,11 @@ class Collection(BaseCollection):
|
|||||||
return os.path.join(filesystem_folder, "collection-root")
|
return os.path.join(filesystem_folder, "collection-root")
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def _atomic_write(self, path, mode="w"):
|
def _atomic_write(self, path, mode="w", newline=None):
|
||||||
directory = os.path.dirname(path)
|
directory = os.path.dirname(path)
|
||||||
tmp = NamedTemporaryFile(
|
tmp = NamedTemporaryFile(
|
||||||
mode=mode, dir=directory, encoding=self.encoding,
|
mode=mode, dir=directory, encoding=self.encoding,
|
||||||
delete=False, prefix=".Radicale.tmp-")
|
delete=False, prefix=".Radicale.tmp-", newline=newline)
|
||||||
try:
|
try:
|
||||||
yield tmp
|
yield tmp
|
||||||
if self.configuration.getboolean("storage", "fsync"):
|
if self.configuration.getboolean("storage", "fsync"):
|
||||||
@ -606,7 +606,7 @@ class Collection(BaseCollection):
|
|||||||
path = path_to_filesystem(self._filesystem_path, href)
|
path = path_to_filesystem(self._filesystem_path, href)
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
return None
|
return None
|
||||||
with open(path, encoding=self.encoding) as fd:
|
with open(path, encoding=self.encoding, newline="") as fd:
|
||||||
text = fd.read()
|
text = fd.read()
|
||||||
last_modified = time.strftime(
|
last_modified = time.strftime(
|
||||||
"%a, %d %b %Y %H:%M:%S GMT",
|
"%a, %d %b %Y %H:%M:%S GMT",
|
||||||
@ -623,7 +623,7 @@ class Collection(BaseCollection):
|
|||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
raise ComponentExistsError(href)
|
raise ComponentExistsError(href)
|
||||||
item = Item(self, vobject_item, href)
|
item = Item(self, vobject_item, href)
|
||||||
with self._atomic_write(path) as fd:
|
with self._atomic_write(path, newline="") as fd:
|
||||||
fd.write(item.serialize())
|
fd.write(item.serialize())
|
||||||
return item
|
return item
|
||||||
|
|
||||||
@ -634,7 +634,7 @@ class Collection(BaseCollection):
|
|||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
raise ComponentNotFoundError(href)
|
raise ComponentNotFoundError(href)
|
||||||
item = Item(self, vobject_item, href)
|
item = Item(self, vobject_item, href)
|
||||||
with self._atomic_write(path) as fd:
|
with self._atomic_write(path, newline="") as fd:
|
||||||
fd.write(item.serialize())
|
fd.write(item.serialize())
|
||||||
return item
|
return item
|
||||||
|
|
||||||
@ -695,7 +695,7 @@ class Collection(BaseCollection):
|
|||||||
continue
|
continue
|
||||||
path = os.path.join(self._filesystem_path, href)
|
path = os.path.join(self._filesystem_path, href)
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
with open(path, encoding=self.encoding) as fd:
|
with open(path, encoding=self.encoding, newline="") as fd:
|
||||||
items.append(vobject.readOne(fd.read()))
|
items.append(vobject.readOne(fd.read()))
|
||||||
if self.get_meta("tag") == "VCALENDAR":
|
if self.get_meta("tag") == "VCALENDAR":
|
||||||
collection = vobject.iCalendar()
|
collection = vobject.iCalendar()
|
||||||
|
Loading…
Reference in New Issue
Block a user