Skip to content

Commit

Permalink
file manager: copy from other bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
kpsherva committed Nov 13, 2023
1 parent 085f186 commit 8155b55
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions invenio_records_resources/records/systemfields/files/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,23 @@ def copy(self, src_files, copy_obj=True):
if not self.enabled:
return

object_version_ids = [rf.object_version_id for rf in src_files.values() if rf.object_version_id]

if copy_obj:
object_versions = ObjectVersion.copy_many(object_version_ids, self.bucket)
ovs = ObjectVersion.copy_from(
src_files.bucket, destination_bucket=self.bucket
)
else:
object_versions = ObjectVersion.query.filter(
ObjectVersion.version_id.in_(object_version_ids)
).all()
ovs = ObjectVersion.get_by_bucket(src_files.bucket)

key_object_versions = {obj.key: obj for obj in object_versions}
ovs_by_key = {obj.key: obj for obj in ovs}

for key, rf in src_files.items():
if rf.metadata is not None:
self[key] = key_object_versions.get(key), rf.metadata
# this part is slightly confusing, intuitively setter should accept
# only one type of object (FileRecord instance) but it also accepts
# Object Version - between other types
self[key] = ovs_by_key[key], rf.metadata
else:
self[key] = key_object_versions.get(key)
self[key] = ovs_by_key[key]

self.default_preview = src_files.default_preview
self.order = src_files.order
Expand Down

0 comments on commit 8155b55

Please sign in to comment.