Remove etags from raw data
Remove all etags that are directly calculated from data that's read from files. 1. They are not used anywhere (luckily). 2. Etags that are send to clients are calculated from the output of vobject's serialize method. If files are edited externally and vobject normalizes them (like wrapping long lines or replacing all line endings by \r\n), the etags that are sent to the client and the etags that are calculated from raw data will never match. If a new version of vobject is released and the formatting changes slightly, the checks will also always fail.
This commit is contained in:
parent
35d12ee97e
commit
0060130c3b
@ -306,7 +306,7 @@ class BaseCollection:
|
|||||||
the filters and this implementation.
|
the filters and this implementation.
|
||||||
This returns all event by default
|
This returns all event by default
|
||||||
"""
|
"""
|
||||||
return [self.get(href) for href, _ in self.list()]
|
return [self.get(href) for href in self.list()]
|
||||||
|
|
||||||
def has(self, href):
|
def has(self, href):
|
||||||
"""Check if an item exists by its href.
|
"""Check if an item exists by its href.
|
||||||
@ -321,17 +321,17 @@ class BaseCollection:
|
|||||||
"""Upload a new item."""
|
"""Upload a new item."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def update(self, href, vobject_item, etag=None):
|
def update(self, href, vobject_item):
|
||||||
"""Update an item.
|
"""Update an item.
|
||||||
|
|
||||||
Functionally similar to ``delete`` plus ``upload``, but might bring
|
Functionally similar to ``delete`` plus ``upload``, but might bring
|
||||||
performance benefits on some storages when used cleverly.
|
performance benefits on some storages when used cleverly.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.delete(href, etag)
|
self.delete(href)
|
||||||
self.upload(href, vobject_item)
|
self.upload(href, vobject_item)
|
||||||
|
|
||||||
def delete(self, href=None, etag=None):
|
def delete(self, href=None):
|
||||||
"""Delete an item.
|
"""Delete an item.
|
||||||
|
|
||||||
When ``href`` is ``None``, delete the collection.
|
When ``href`` is ``None``, delete the collection.
|
||||||
@ -500,7 +500,7 @@ class Collection(BaseCollection):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for item in collection.list():
|
for item in collection.list():
|
||||||
yield collection.get(item[0])
|
yield collection.get(item)
|
||||||
|
|
||||||
for href in os.listdir(filesystem_path):
|
for href in os.listdir(filesystem_path):
|
||||||
if not is_safe_filesystem_path_component(href):
|
if not is_safe_filesystem_path_component(href):
|
||||||
@ -593,8 +593,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:
|
yield href
|
||||||
yield href, get_etag(fd.read())
|
|
||||||
|
|
||||||
def get(self, href):
|
def get(self, href):
|
||||||
if not href:
|
if not href:
|
||||||
@ -628,22 +627,18 @@ class Collection(BaseCollection):
|
|||||||
fd.write(item.serialize())
|
fd.write(item.serialize())
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def update(self, href, vobject_item, etag=None):
|
def update(self, href, vobject_item):
|
||||||
if not is_safe_filesystem_path_component(href):
|
if not is_safe_filesystem_path_component(href):
|
||||||
raise UnsafePathError(href)
|
raise UnsafePathError(href)
|
||||||
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):
|
||||||
raise ComponentNotFoundError(href)
|
raise ComponentNotFoundError(href)
|
||||||
with open(path, encoding=self.encoding) as fd:
|
|
||||||
text = fd.read()
|
|
||||||
if etag and etag != get_etag(text):
|
|
||||||
raise EtagMismatchError(etag, get_etag(text))
|
|
||||||
item = Item(self, vobject_item, href)
|
item = Item(self, vobject_item, href)
|
||||||
with self._atomic_write(path) as fd:
|
with self._atomic_write(path) as fd:
|
||||||
fd.write(item.serialize())
|
fd.write(item.serialize())
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def delete(self, href=None, etag=None):
|
def delete(self, href=None):
|
||||||
if href is None:
|
if href is None:
|
||||||
# Delete the collection
|
# Delete the collection
|
||||||
if os.path.isdir(self._filesystem_path):
|
if os.path.isdir(self._filesystem_path):
|
||||||
@ -665,10 +660,6 @@ 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):
|
||||||
raise ComponentNotFoundError(href)
|
raise ComponentNotFoundError(href)
|
||||||
with open(path, encoding=self.encoding) as fd:
|
|
||||||
text = fd.read()
|
|
||||||
if etag and etag != get_etag(text):
|
|
||||||
raise EtagMismatchError(etag, get_etag(text))
|
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
self._sync_directory(os.path.dirname(path))
|
self._sync_directory(os.path.dirname(path))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user