summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-11-09 04:10:05 -0300
committerVictor Shyba <victor1984@riseup.net>2017-11-13 18:17:15 -0300
commit914579325d242e2643a964bbf1b271435b5c66cc (patch)
tree87282e49e2fe934b847b590fefa0dbad1f54edc7 /src/leap
parent91d7cd4961c0e158d1dc57e16d243d2394e04d40 (diff)
[feature] list deleted files from server
-- Related: #8961
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/soledad/client/_db/blobs/__init__.py7
-rw-r--r--src/leap/soledad/server/_blobs.py19
2 files changed, 21 insertions, 5 deletions
diff --git a/src/leap/soledad/client/_db/blobs/__init__.py b/src/leap/soledad/client/_db/blobs/__init__.py
index 45fae024..a5b7d6e3 100644
--- a/src/leap/soledad/client/_db/blobs/__init__.py
+++ b/src/leap/soledad/client/_db/blobs/__init__.py
@@ -159,7 +159,7 @@ class BlobManager(BlobsSynchronizer):
return self.remote_list(namespace=namespace, only_count=True)
@defer.inlineCallbacks
- def remote_list(self, namespace='', order_by=None,
+ def remote_list(self, namespace='', order_by=None, deleted=False,
filter_flag=False, only_count=False):
"""
List blobs from server, with filtering and ordering capabilities.
@@ -172,6 +172,9 @@ class BlobManager(BlobsSynchronizer):
date or +date - Ascending order (older first)
-date - Descending order (newer first)
:type order_by: str
+ :param deleted:
+ Optional paramter to return only deleted blobs.
+ :type only_count: bool
:param filter_flag:
Optional parameter to filter listing to results containing the
specified tag.
@@ -188,6 +191,8 @@ class BlobManager(BlobsSynchronizer):
params = {'namespace': namespace} if namespace else {}
if order_by:
params['order_by'] = order_by
+ if deleted:
+ params['deleted'] = deleted
if filter_flag:
params['filter_flag'] = filter_flag
if only_count:
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py
index 55ef0d86..f44afd94 100644
--- a/src/leap/soledad/server/_blobs.py
+++ b/src/leap/soledad/server/_blobs.py
@@ -70,6 +70,9 @@ class FilesystemBlobsBackend(object):
os.makedirs(blobs_path)
self.path = blobs_path
+ def __touch(self, path):
+ open(path, 'a')
+
def read_blob(self, user, blob_id, request, namespace=''):
logger.info('reading blob: %s - %s@%s' % (user, blob_id, namespace))
path = self._get_path(user, blob_id, namespace)
@@ -138,6 +141,7 @@ class FilesystemBlobsBackend(object):
os.unlink(blob_path + '.flags')
except Exception:
pass
+ self.__touch(blob_path + '.deleted')
def get_blob_size(user, blob_id, namespace=''):
raise NotImplementedError
@@ -150,13 +154,18 @@ class FilesystemBlobsBackend(object):
return json.dumps({"count": count})
def list_blobs(self, user, request, namespace='', order_by=None,
- filter_flag=False):
+ deleted=False, filter_flag=False):
namespace = namespace or 'default'
blob_ids = []
base_path = self._get_path(user, namespace=namespace)
+
+ def match(name):
+ if deleted:
+ return name.endswith('.deleted')
+ return VALID_STRINGS.match(name)
for root, dirs, filenames in os.walk(base_path):
blob_ids += [os.path.join(root, name) for name in filenames
- if not name.endswith('.flags')]
+ if match(name)]
if order_by in ['date', '+date']:
blob_ids.sort(key=lambda x: os.path.getmtime(x))
elif order_by == '-date':
@@ -165,7 +174,8 @@ class FilesystemBlobsBackend(object):
raise Exception("Unsupported order_by parameter: %s" % order_by)
if filter_flag:
blob_ids = list(self._filter_flag(blob_ids, filter_flag))
- blob_ids = [os.path.basename(path) for path in blob_ids]
+ blob_ids = [os.path.basename(path).replace('.deleted', '')
+ for path in blob_ids]
return json.dumps(blob_ids)
def _filter_flag(self, blob_paths, flag):
@@ -267,8 +277,9 @@ class BlobsResource(resource.Resource):
elif not blob_id:
order = request.args.get('order_by', [None])[0]
filter_flag = request.args.get('filter_flag', [False])[0]
+ deleted = request.args.get('deleted', [False])[0]
return self._handler.list_blobs(user, request, namespace,
- order_by=order,
+ order_by=order, deleted=deleted,
filter_flag=filter_flag)
only_flags = request.args.get('only_flags', [False])[0]
if only_flags: