Properties inside of collection
* Creation and deletion of collections can be atomic. * The properties file of the root collection is not outside of the filesystem_folder. * It's easier to delete and move collections by hand. * This breaks backward compatibility.
This commit is contained in:
parent
5ed60ce09d
commit
13c693ba35
@ -333,6 +333,8 @@ class Collection(BaseCollection):
|
|||||||
self.path = sanitize_path(path).strip("/")
|
self.path = sanitize_path(path).strip("/")
|
||||||
self.storage_encoding = self.configuration.get("encoding", "stock")
|
self.storage_encoding = self.configuration.get("encoding", "stock")
|
||||||
self._filesystem_path = path_to_filesystem(folder, self.path)
|
self._filesystem_path = path_to_filesystem(folder, self.path)
|
||||||
|
self._props_path = path_to_filesystem(self._filesystem_path,
|
||||||
|
"collection.props")
|
||||||
split_path = self.path.split("/")
|
split_path = self.path.split("/")
|
||||||
if len(split_path) > 1:
|
if len(split_path) > 1:
|
||||||
# URL with at least one folder
|
# URL with at least one folder
|
||||||
@ -520,9 +522,6 @@ class Collection(BaseCollection):
|
|||||||
# Delete the collection
|
# Delete the collection
|
||||||
if os.path.isdir(self._filesystem_path):
|
if os.path.isdir(self._filesystem_path):
|
||||||
shutil.rmtree(self._filesystem_path)
|
shutil.rmtree(self._filesystem_path)
|
||||||
props_path = self._filesystem_path + ".props"
|
|
||||||
if os.path.isfile(props_path):
|
|
||||||
os.remove(props_path)
|
|
||||||
else:
|
else:
|
||||||
# Delete an item
|
# Delete an item
|
||||||
if not is_safe_filesystem_path_component(href):
|
if not is_safe_filesystem_path_component(href):
|
||||||
@ -539,16 +538,14 @@ class Collection(BaseCollection):
|
|||||||
os.remove(path)
|
os.remove(path)
|
||||||
|
|
||||||
def get_meta(self, key):
|
def get_meta(self, key):
|
||||||
props_path = self._filesystem_path + ".props"
|
if os.path.exists(self._props_path):
|
||||||
if os.path.exists(props_path):
|
with open(self._props_path, encoding=self.storage_encoding) as prop:
|
||||||
with open(props_path, encoding=self.storage_encoding) as prop:
|
|
||||||
return json.load(prop).get(key)
|
return json.load(prop).get(key)
|
||||||
|
|
||||||
def set_meta(self, key, value):
|
def set_meta(self, key, value):
|
||||||
props_path = self._filesystem_path + ".props"
|
|
||||||
properties = {}
|
properties = {}
|
||||||
if os.path.exists(props_path):
|
if os.path.exists(self._props_path):
|
||||||
with open(props_path, encoding=self.storage_encoding) as prop:
|
with open(self._props_path, encoding=self.storage_encoding) as prop:
|
||||||
properties.update(json.load(prop))
|
properties.update(json.load(prop))
|
||||||
|
|
||||||
if value:
|
if value:
|
||||||
@ -556,7 +553,7 @@ class Collection(BaseCollection):
|
|||||||
else:
|
else:
|
||||||
properties.pop(key, None)
|
properties.pop(key, None)
|
||||||
|
|
||||||
with self._atomic_write(props_path, "w+") as prop:
|
with self._atomic_write(self._props_path, "w+") as prop:
|
||||||
json.dump(properties, prop)
|
json.dump(properties, prop)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user