Expose low level MOVE operation in storage.BaseCollection

This commit is contained in:
Unrud 2016-08-06 04:47:17 +02:00
parent 17ff22cae4
commit 23582c8208
2 changed files with 21 additions and 6 deletions

View File

@ -496,12 +496,7 @@ class Application:
if not to_collection: if not to_collection:
return client.CONFLICT, {}, None return client.CONFLICT, {}, None
to_href = posixpath.basename(to_path.strip("/")) to_href = posixpath.basename(to_path.strip("/"))
if path.strip("/") != to_path.strip("/"): self.Collection.move(item, to_collection, to_href)
if to_item:
to_collection.update(to_href, item.item)
else:
to_collection.upload(to_href, item.item)
item.collection.delete(item.href)
return client.CREATED, {}, None return client.CREATED, {}, None
def do_OPTIONS(self, environ, path, content, user): def do_OPTIONS(self, environ, path, content, user):

View File

@ -265,6 +265,26 @@ class BaseCollection:
""" """
raise NotImplementedError raise NotImplementedError
@classmethod
def move(cls, item, to_collection, to_href):
"""Move an object.
``item`` is the item to move.
``to_collection`` is the target collection.
``to_href`` is the target name in ``to_collection``. An item with the
same name might already exist.
"""
if item.collection.path == to_collection.path and item.href == to_href:
return
if to_collection.has(to_href):
to_collection.update(to_href, item.item)
else:
to_collection.upload(to_href, item.item)
item.collection.delete(item.href)
@property @property
def etag(self): def etag(self):
return get_etag(self.serialize()) return get_etag(self.serialize())