Skip to content

Commit

Permalink
wip: sync file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo committed Aug 1, 2023
1 parent 3bef443 commit e81c90b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 36 deletions.
38 changes: 10 additions & 28 deletions invenio_drafts_resources/services/records/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,11 @@ def edit(self, identity, draft=None, record=None):
draft_files = self.get_record_files(draft)
draft_files.create_bucket()

# we don't copy file objects - will edit by bucket sync
draft_files.copy(record_files, copy_obj=False)
# force going through the new version
# we copy always file objects and tear them down when publish
draft_files.copy(record_files)
if lock_files:
# draft_files.copy(record_files, copy_obj=False)
# force going through the new version
draft_files.lock()
# else:
# draft_files.copy(record_files, copy_obj=True)

def new_version(self, identity, draft=None, record=None):
"""New version callback."""
Expand All @@ -198,7 +195,6 @@ def _publish_new(self, identity, draft, record):

record_files.set_bucket(draft_bucket)
record_files.copy(draft_files, copy_obj=False)

# Lock the bucket
record_files.lock()

Expand All @@ -209,33 +205,19 @@ def _publish_new(self, identity, draft, record):

def _publish_edit(self, identity, draft, record):
"""Action when publishing an edit to an existing record."""
# For now, sync() only # changes the default_preview and order
# the lock and unlock management is done here in the component
enforce_lock_files = self.service.config.lock_edit_published_files(record)
record_files = self.get_record_files(record)
draft_files = self.get_record_files(draft)

# interestingly, when we compare file manager instances, we need to have
# enabled files!
files_changed = draft_files.enabled and record_files != draft_files

record_files_bucket = record_files.bucket
draft_files_bucket = draft_files.bucket

# sync only metadata
record_files.sync(draft_files)

if not enforce_lock_files and files_changed:
record_files.unlock()
draft_files_bucket.sync(bucket=record_files_bucket, delete_extras=True)
record_files.lock()
# sync draft files with record
record_files.unlock()
record_files.sync(draft_files, delete_extras=True)
record_files.lock()

# Teardown the bucket and files created in edit().
if enforce_lock_files:
if draft_files.bucket.locked:
draft_files.unlock()
if draft_files.enabled:
draft_files.delete_all(remove_obj=False)

draft_files.delete_all()
draft_files.remove_bucket(force=True)

def publish(self, identity, draft=None, record=None):
Expand Down Expand Up @@ -277,7 +259,7 @@ def delete_draft(self, identity, draft=None, record=None, force=False):
if files_locked:
draft_files.unlock()
if draft_files.enabled:
draft_files.delete_all(remove_obj=False)
draft_files.delete_all()
draft_files.remove_bucket(force=True)

def import_files(self, identity, draft=None, record=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def edit(self, identity, draft=None, record=None):
# re-fetch the files attribute - above data getter sets the attribute
draft_files = self.get_record_files(draft)
draft_files.create_bucket()
# we don't copy file objects - will edit by bucket sync
draft_files.copy(record_files, copy_obj=False)
# we copy always file objects and tear them down when publish
draft_files.copy(record_files)
# in the media files we don't lock the bucket
# - they can be simply edited from draft

Expand All @@ -100,16 +100,13 @@ def _publish_edit(self, identity, draft, record):
record_files = self.get_record_files(record)
draft_files = self.get_record_files(draft)

record_files_bucket = record_files.bucket
draft_files_bucket = draft_files.bucket

record_files.sync(draft_files)
record_files.unlock()
draft_files_bucket.sync(bucket=record_files_bucket, delete_extras=True)
record_files.sync(draft_files)
# draft_files_bucket.sync(bucket=record_files_bucket, delete_extras=True)
record_files.lock()
# Teardown the bucket and files created in edit().
if draft_files.enabled:
draft_files.delete_all(remove_obj=False)
draft_files.delete_all()
draft_files.remove_bucket(force=True)

def new_version(self, identity, draft=None, record=None):
Expand Down

0 comments on commit e81c90b

Please sign in to comment.