Skip to content

Commit d475679

Browse files
d-w-moorealanking
authored andcommitted
[#557] de-duplicate acl lists in case of multiple replicas.
1 parent c3963c2 commit d475679

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

irods/access.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import collections
22
import copy
33
import six
4+
from irods.path import iRODSPath
45

56
class _Access_LookupMeta(type):
67
def __getitem__(self, key): return self.codes[key]
@@ -63,6 +64,18 @@ def __init__(self, access_name, path, user_name='', user_zone='', user_type=None
6364
self.user_zone = user_zone
6465
self.user_type = user_type
6566

67+
def __eq__(self,other):
68+
return self.access_name == other.access_name and \
69+
iRODSPath(self.path) == iRODSPath(other.path) and \
70+
self.user_name == other.user_name and \
71+
self.user_zone == other.user_zone
72+
73+
def __hash__(self):
74+
return hash((self.access_name,
75+
iRODSPath(self.path),
76+
self.user_name,
77+
self.user_zone))
78+
6679
def copy(self, decanonicalize = False):
6780
other = copy.deepcopy(self)
6881
if decanonicalize:

irods/manager/access_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,15 @@ def __get_raw(self, target, **kw):
116116
elif users_out is None: pass
117117
else: raise TypeError
118118

119-
acls = [ iRODSAccess ( r[access_column.name],
119+
# Instantiate as set before converting to a list, in order to remove duplicate iRODSAccess
120+
# objects. [#557]
121+
122+
acls = list({ iRODSAccess ( r[access_column.name],
120123
target.path,
121124
user_lookup[r[access_column.user_id]].name,
122125
user_lookup[r[access_column.user_id]].zone,
123126
user_lookup[r[access_column.user_id]].type,
124-
) for r in rows ]
127+
) for r in rows })
125128
return acls
126129

127130

irods/test/data_obj_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ def create_resc_hierarchy (self, Root, Leaf = None):
130130
self.sess.resources.remove(Leaf)
131131
self.sess.resources.remove(Root)
132132

133+
def test_acls_are_uniquely_listed_for_replicated_data_objects__issue_557(self):
134+
with self.create_simple_resc() as newResc1:
135+
d = None
136+
try:
137+
path = self.coll_path + "/" + unique_name(my_function_name(), datetime.now())
138+
d = self.sess.data_objects.create(path)
139+
acls_pre = self.sess.acls.get(d)
140+
d.replicate(resource = newResc1)
141+
acls_post = self.sess.acls.get(d)
142+
self.assertEqual(len(acls_pre), len(acls_post))
143+
finally:
144+
if d:
145+
d.unlink(force = True)
133146

134147
def _helper_for_testing_that_replicate_obeys_default_resource_setting__issue_459(self, get_session_function):
135148
with self.create_simple_resc() as newResc1:

0 commit comments

Comments
 (0)