Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar_network/db/storage.py
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2014-01-05 07:45:41 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2014-01-05 07:45:41 (GMT)
commit28f17ea51f50fd75025bc598cbca1351aad4be3f (patch)
treea9664ac563352705f02b3fecd6ef094bc5c511ea /sugar_network/db/storage.py
parent5955e4a46d48dd6099e56e17b7fa545be46de540 (diff)
Delete blobs while updating existing properties
Diffstat (limited to 'sugar_network/db/storage.py')
-rw-r--r--sugar_network/db/storage.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/sugar_network/db/storage.py b/sugar_network/db/storage.py
index 83fb0c7..a280a13 100644
--- a/sugar_network/db/storage.py
+++ b/sugar_network/db/storage.py
@@ -135,14 +135,16 @@ class Record(object):
meta['mtime'] = int(os.stat(path).st_mtime)
return meta
- def set(self, prop, mtime=None, **meta):
+ def set(self, prop, mtime=None, cleanup_blob=False, blob=None, **meta):
if not exists(self._root):
os.makedirs(self._root)
meta_path = join(self._root, prop)
+ dst_blob_path = meta_path + _BLOB_SUFFIX
- if 'blob' in meta:
- dst_blob_path = meta_path + _BLOB_SUFFIX
- blob = meta.pop('blob')
+ if (cleanup_blob or blob is not None) and exists(dst_blob_path):
+ os.unlink(dst_blob_path)
+
+ if blob is not None:
if hasattr(blob, 'read'):
with toolkit.new_file(dst_blob_path) as f:
shutil.copyfileobj(blob, f)