diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2014-01-05 07:45:41 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2014-01-05 07:45:41 (GMT) |
commit | 28f17ea51f50fd75025bc598cbca1351aad4be3f (patch) | |
tree | a9664ac563352705f02b3fecd6ef094bc5c511ea /sugar_network/db/storage.py | |
parent | 5955e4a46d48dd6099e56e17b7fa545be46de540 (diff) |
Delete blobs while updating existing properties
Diffstat (limited to 'sugar_network/db/storage.py')
-rw-r--r-- | sugar_network/db/storage.py | 10 |
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) |