Revision cf4a7a7b
b/snf-pithos-backend/pithos/backends/lib/sqlite/node.py | ||
---|---|---|
207 | 207 |
""" |
208 | 208 |
|
209 | 209 |
placeholders = ','.join('?' for path in paths) |
210 |
q = "select path, node from nodes where path in (%s)" % placeholders
|
|
210 |
q = "select node from nodes where path in (%s)" % placeholders |
|
211 | 211 |
self.execute(q, paths) |
212 |
return self.fetchall() |
|
212 |
r = self.fetchall() |
|
213 |
if r is not None: |
|
214 |
return [row[0] for row in r] |
|
215 |
return None |
|
213 | 216 |
|
214 | 217 |
def node_get_properties(self, node): |
215 | 218 |
"""Return the node's (parent, path). |
... | ... | |
492 | 495 |
self.statistics_update_ancestors(node, 1, size, mtime, cluster) |
493 | 496 |
return serial, mtime |
494 | 497 |
|
495 |
def version_lookup(self, node, before=inf, cluster=0): |
|
498 |
def version_lookup(self, node, before=inf, cluster=0, all_props=True):
|
|
496 | 499 |
"""Lookup the current version of the given node. |
497 | 500 |
Return a list with its properties: |
498 | 501 |
(serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster) |
499 | 502 |
or None if the current version is not found in the given cluster. |
500 | 503 |
""" |
501 | 504 |
|
502 |
q = ("select serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster "
|
|
505 |
q = ("select %s "
|
|
503 | 506 |
"from versions " |
504 | 507 |
"where serial = (select max(serial) " |
505 | 508 |
"from versions " |
506 | 509 |
"where node = ? and mtime < ?) " |
507 | 510 |
"and cluster = ?") |
511 |
if not all_props: |
|
512 |
q = q % "serial" |
|
513 |
else: |
|
514 |
q = q % "serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster" |
|
515 |
|
|
508 | 516 |
self.execute(q, (node, before, cluster)) |
509 | 517 |
props = self.fetchone() |
510 | 518 |
if props is not None: |
511 | 519 |
return props |
512 | 520 |
return None |
513 | 521 |
|
514 |
def version_lookup_bulk(self, nodes, before=inf, cluster=0): |
|
522 |
def version_lookup_bulk(self, nodes, before=inf, cluster=0, all_props=True):
|
|
515 | 523 |
"""Lookup the current versions of the given nodes. |
516 | 524 |
Return a list with their properties: |
517 | 525 |
(serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster). |
518 | 526 |
""" |
519 | 527 |
|
520 |
placeholders = ','.join('?' for node in nodes) |
|
521 |
q = ("select serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster " |
|
528 |
q = ("select %s " |
|
522 | 529 |
"from versions " |
523 | 530 |
"where serial in (select max(serial) " |
524 | 531 |
"from versions " |
525 | 532 |
"where node in (%s) and mtime < ? group by node) " |
526 |
"and cluster = ?" % placeholders) |
|
533 |
"and cluster = ?") |
|
534 |
placeholders = ','.join('?' for node in nodes) |
|
535 |
if not all_props: |
|
536 |
q = q % ("serial", placeholders) |
|
537 |
else: |
|
538 |
q = q % ("serial, node, hash, size, type, source, mtime, muser, uuid, checksum, cluster", placeholders) |
|
539 |
|
|
527 | 540 |
args = nodes |
528 | 541 |
args.extend((before, cluster)) |
529 | 542 |
self.execute(q, args) |
b/snf-pithos-backend/pithos/backends/modular.py | ||
---|---|---|
334 | 334 |
start, limit = self._list_limits(allowed, marker, limit) |
335 | 335 |
return allowed[start:start + limit] |
336 | 336 |
node = self.node.node_lookup(account) |
337 |
return [x[0] for x in self._list_object_properties(node, account, '', '/', marker, limit, False, None, [], until)] |
|
337 |
containers = [x[0] for x in self._list_object_properties(node, account, '', '/', marker, limit, False, None, [], until)] |
|
338 |
start, limit = self._list_limits([x[0] for x in containers], marker, limit) |
|
339 |
return containers[start:start + limit] |
|
338 | 340 |
|
339 | 341 |
@backend_method |
340 | 342 |
def list_container_meta(self, user, account, container, domain, until=None): |
... | ... | |
469 | 471 |
def _list_objects(self, user, account, container, prefix, delimiter, marker, limit, virtual, domain, keys, shared, until, size_range, all_props, public): |
470 | 472 |
if user != account and until: |
471 | 473 |
raise NotAllowedError |
474 |
if shared and public: |
|
475 |
# get shared first |
|
476 |
shared = self._list_object_permissions(user, account, container, prefix, shared=True, public=False) |
|
477 |
objects = [] |
|
478 |
if shared: |
|
479 |
path, node = self._lookup_container(account, container) |
|
480 |
shared = self._get_formatted_paths(shared) |
|
481 |
objects = self._list_object_properties(node, path, prefix, delimiter, marker, limit, virtual, domain, keys, until, size_range, shared, all_props) |
|
482 |
|
|
483 |
# get public |
|
484 |
objects.extend(self._list_public_object_properties(user, account, container, prefix, all_props)) |
|
485 |
|
|
486 |
objects.sort(key=lambda x: x[0]) |
|
487 |
start, limit = self._list_limits([x[0] for x in objects], marker, limit) |
|
488 |
return objects[start:start + limit] |
|
489 |
elif public: |
|
490 |
objects = self._list_public_object_properties(user, account, container, prefix, all_props) |
|
491 |
start, limit = self._list_limits([x[0] for x in objects], marker, limit) |
|
492 |
return objects[start:start + limit] |
|
493 |
|
|
472 | 494 |
allowed = self._list_object_permissions(user, account, container, prefix, shared, public) |
473 |
if (shared or public) and not allowed:
|
|
495 |
if shared and not allowed:
|
|
474 | 496 |
return [] |
475 | 497 |
path, node = self._lookup_container(account, container) |
476 | 498 |
allowed = self._get_formatted_paths(allowed) |
477 |
return self._list_object_properties(node, path, prefix, delimiter, marker, limit, virtual, domain, keys, until, size_range, allowed, all_props) |
|
499 |
objects = self._list_object_properties(node, path, prefix, delimiter, marker, limit, virtual, domain, keys, until, size_range, allowed, all_props) |
|
500 |
start, limit = self._list_limits([x[0] for x in objects], marker, limit) |
|
501 |
return objects[start:start + limit] |
|
478 | 502 |
|
503 |
def _list_public_object_properties(self, user, account, container, prefix, all_props): |
|
504 |
public = self._list_object_permissions(user, account, container, prefix, shared=False, public=True) |
|
505 |
paths, nodes = self._lookup_objects(public) |
|
506 |
path = '/'.join((account, container)) |
|
507 |
cont_prefix = path + '/' |
|
508 |
paths = [x[len(cont_prefix):] for x in paths] |
|
509 |
props = self.node.version_lookup_bulk(nodes, all_props=all_props) |
|
510 |
objects = [(path,) + props for path, props in zip(paths, props)] |
|
511 |
return objects |
|
512 |
|
|
479 | 513 |
def _list_objects_no_limit(self, user, account, container, prefix, delimiter, virtual, domain, keys, shared, until, size_range, all_props, public): |
480 | 514 |
objects = [] |
481 | 515 |
while True: |
... | ... | |
944 | 978 |
raise NameError('Object does not exist') |
945 | 979 |
return path, node |
946 | 980 |
|
981 |
def _lookup_objects(self, paths): |
|
982 |
nodes = self.node.node_lookup_bulk(paths) |
|
983 |
if nodes is None: |
|
984 |
raise NameError('Object does not exist') |
|
985 |
return paths, nodes |
|
986 |
|
|
947 | 987 |
def _get_properties(self, node, until=None): |
948 | 988 |
"""Return properties until the timestamp given.""" |
949 | 989 |
|
... | ... | |
1074 | 1114 |
objects.extend([(p, None) for p in prefixes] if virtual else []) |
1075 | 1115 |
objects.sort(key=lambda x: x[0]) |
1076 | 1116 |
objects = [(x[0][len(cont_prefix):],) + x[1:] for x in objects] |
1117 |
return objects |
|
1077 | 1118 |
|
1078 |
start, limit = self._list_limits([x[0] for x in objects], marker, limit) |
|
1079 |
return objects[start:start + limit] |
|
1080 |
|
|
1081 | 1119 |
# Reporting functions. |
1082 | 1120 |
|
1083 | 1121 |
def _report_size_change(self, user, account, size, details={}): |
Also available in: Unified diff