addressed code review comment to simplify code logic a bit
@@ -1462,21 +1462,15 @@ class AbstractResource(ResourcePermissionsMixin):
for fl in self.files.all():
if fl.fed_resource_file_name_or_path:
istorage = IrodsStorage('federated')
- if fl.fed_resource_file_name_or_path.find(self.short_id) >= 0:
- istorage.delete('{}/{}'.format(self.resource_federation_path,
- fl.fed_resource_file_name_or_path))
- elif self.resource_federation_path:
- istorage.delete('{}/{}/{}'.format(self.resource_federation_path,
- self.short_id,
- fl.fed_resource_file_name_or_path))
- else:
- # this scenario happens when adding a file from a federated zone into
- # a resource that is already created in the default hydroshare zone, in
- # which case resource_federation_path on the resource is empty, but
- # fede_resource_file_name_or_path stores the relative path without federated
- # zone on the path since the file ends up being stored in hydroshare zone
- istorage.delete('{}/{}'.format(self.short_id,
- fl.fed_resource_file_name_or_path))
+ # ensure fed_res_file_path holds relative path in the format of data/contents/...
+ # so that a uniform path can be formed by concatenating with self.root_path for
+ # file deletion by irods storage
+ fed_res_file_path = fl.fed_resource_file_name_or_path
+ idx = fed_res_file_path.find(self.short_id)
+ if idx >= 0:
+ s_idx = idx + len(self.short_id) + 1
+ fed_res_file_path = fed_res_file_path[s_idx:]
+ istorage.delete(os.path.join(self.root_path, fed_res_file_path))
elif fl.resource_file:
fl.resource_file.delete()
elif fl.fed_resource_file:
