Repository navigation
Description
Problem
A save that updates a version in place (no new version) deletes a binary field's files and metadata immediately, during the save, outside the database transaction. If the save then rolls back (a validation error, a failing workflow sub-action, a database error), the version comes back pointing at a file that no longer exists, and opening it answers 404.
Which saves: ESContentletAPIImpl.saveDraft saves in place (checkinWithoutVersioning) when the working version is not live and the same user saves it again, which is the usual way of editing your own draft. In that case handleBinaries works on the existing version's directory (newInode equals oldInode), and:
- Clearing a binary field (the editor removes the file, or an API save sends the
-removed-marker) runsFileUtil.deltree(binaryFieldFolder)and, for file assets,fileMetadataAPI.removeMetadata(contentlet). - Replacing a binary field's file also runs
FileUtil.deltree(binaryFieldFolder)before copying the new file in. After a rollback the row names the old file, which is gone.
Not affected: a normal save that creates a new version only touches the new version's own directory and metadata, so a rollback removes that version and leaves the previous one intact. OrderMenuAction also saves in place, but changes only the sort order, never a binary.
Relation to #37782
Same class of defect as #37782, which fixed it for destroys (PR #38000): a destroy now removes binaries, the resized-image cache and metadata only after the outermost transaction commits. This save path was found while planning that fix and left out on purpose: the approved spec scoped the change to destroy paths, and changing save behaviour needs its own review.
Lower priority than #37782: this needs an in-place draft save that clears or replaces a file and then rolls back, and it affects that one field. #37782 could lose every file a folder delete reached.
Suggested fix
Reuse BinaryRemovalAfterCommit from PR #38000 for the in-place case:
- Clearing: work out the directory and metadata keys at save time (
fileMetadataAPI.prepareMetadataRemoval) and schedule only the removal for after the outermost commit. - Replacing: keep the old file until commit, for example by writing the new file beside it and removing the old one after commit, so a rollback still finds the file the row names.
A save outside a transaction keeps today's behaviour. Saves that create a new version need no change.
Also in scope: metadata delete failures that are never logged
Raised in review of PR #38000. With file system storage, FileSystemStoragePersistenceAPIImpl.deleteObjectAndReferences ends in File.delete(), which returns false on failure instead of throwing. FileMetadataAPIImpl.removeKeys treats false as "nothing to remove", so a metadata file that cannot be deleted stays on disk with no log line. This is pre-existing on main, and it applies to destroys too, not only saves.
It belongs here because the acceptance criterion below ("a failure while removing after commit is logged with what was left on disk") cannot hold for metadata until the storage tells a failed delete apart from a missing entry. Fixing it touches how the storage chain reports deletes and updates its cache (deleteObjectAndReferences / deleteObjectReference across the file system, database and chained storages), so check every implementation, not only the file system one.
Acceptance criteria
- An in-place draft save that clears a binary field and then rolls back leaves the field's file and metadata in place, and the content still opens.
- An in-place draft save that replaces a binary field's file and then rolls back leaves the previous file in place, and the content still opens.
- Both still remove the old file (and, when clearing, the metadata) once the save commits, before the call that committed returns.
- A failure while removing after commit is logged with what was left on disk and does not fail the save.
- Versioned saves and saves outside a transaction behave as today.
- With file system storage, a metadata file that cannot be deleted is logged with its path and storage group, for saves and for destroys, while a metadata entry that is simply missing is still treated as nothing to remove.
Verification
Integration tests for clear and replace, each rolled back and committed, on a file asset and on a content type with a binary field, each confirmed failing on today's code first where today's code is wrong. Plus a guard that a versioned save is unaffected, and a test that a metadata file the file system storage cannot delete is logged rather than silently skipped.
Drafted by Claude Code on behalf of @zJaaal.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsNext Sprint
Activity
[-]Clearing a binary field on save deletes its file before the save commits[/-][+]Saving a draft in place deletes a binary field's file before the save commits[/+][-]Saving a draft in place deletes a binary field's file before the save commits[/-][+]Saving a draft in place deletes a binary field's file before commit, and failed metadata deletes go unlogged[/+]