Skip to content

Folder delete: a failure part-way loses the binaries it already walked, plus three smaller bulk delete defects #37782

Description

@fabrizzio-dotCMS

Description

When a folder delete fails part-way through the tree, the database changes are rolled back but the
files already removed from disk are not restored. The folder, its subfolders and every file
asset stay listed in the product, but the binaries of the files the delete had already reached are
gone: opening them returns 404. The user is told the delete failed, so nothing suggests that
anything was lost.

This is data loss with no warning, and there is no way to recover the file from dotCMS afterwards.

It reproduces with both folder delete entry points, so it predates the bulk delete:

Steps to reproduce

Use a back-end user without the CMS Administrator role (an admin passes every permission check,
so the delete never fails).

  1. Create a folder parent/ with two subfolders, parent/a/ and parent/b/. Subfolders are
    walked in name order, so a/ must sort before b/.
  2. Put a file asset in parent/a/ (any small file, e.g. test.txt) and confirm it opens at
    /parent/a/test.txt.
  3. Give the user's role View, Edit, Edit Permissions and Publish on parent/, inherited by
    its children.
  4. On parent/b/ only, remove Edit Permissions for that role (keep View, Edit, Publish).
  5. As that user, delete parent/ from Content Drive using either entry point above.

Expected

The delete fails because of parent/b/, and nothing under parent/ changes: every folder,
content and file is still there, and /parent/a/test.txt still opens.

Actual

  • The delete fails as expected:
    • bulk delete: the outcome reports parent/ as FAILED, PERMISSION_DENIED;
    • context menu: "User … does not have edit permissions on Folder /parent/b/".
  • The database is unchanged: all folders, contentlets and the file asset's record are still
    there, and the file still shows in Content Drive.
  • The file's binary is gone from disk (/data/shared/assets/<x>/<y>/<inode>/fileAsset/test.txt),
    for every version of the file. /parent/a/test.txt and /dA/<inode>/fileAsset/test.txt return
    404.

Cause

FolderAPIImpl.delete is @WrapInTransaction and recurses depth-first. When it reaches a/, it
calls ContentletAPI.destroy on its contents, and ESContentletAPIImpl.destroyContentlets calls
deleteBinaryFiles, which removes the asset directory from disk immediately
(FileUtil.deltree, ESContentletAPIImpl.java:9408-9420). That removal is outside the
transaction. When the recursion then fails on b/
(FolderAPIImpl.delete re-checks PERMISSION_EDIT_PERMISSIONS on every subfolder), the
transaction rolls back the rows, but the files are already gone.

Any failure after at least one file has been destroyed triggers the same thing, not only
permissions. For example: content locked by another user deeper in the tree, a database trigger
refusing a delete, or a transient database error.

Possible direction

Defer the disk removal until the transaction commits (HibernateUtil.addCommitListener), so a
rollback leaves the files in place. The spec for
#37063 already requires a failed folder to be left "fully deleted or untouched" (FR-023); on disk
that guarantee does not hold today.

Environment

Reproduced on dotcms/dotcms:trunk_0666682 (includes #37685 and #37688), Postgres, Elasticsearch,
single node.

Related


Also in scope: three smaller bulk delete defects

Found while reviewing the bulk folder duplicate (#37062, PR #37760). The duplicate side copied these from bulk delete and has already been fixed. Bulk delete still has all three. Each is small, so they are carried here, not in a ticket of their own.

1. A child is reported covered by its parent even when the parent is never deleted

FolderBulkDeleteProcessor decides COVERED_BY_PARENT up front, from the submitted paths alone (FolderBulkDeleteProcessor.java:196), before it knows whether the parent will actually be deleted.

  • Steps: as a user who may delete /a/b/ but not /a/, select both and run a bulk delete.
  • Actual: /a/ is FAILED; /a/b/ is SKIPPED / COVERED_BY_PARENT and is never deleted. The outcome says the parent took care of the child when nothing did.
  • The same happens when the parent fails for any other reason (IN_USE, PATH_NOT_FOUND, UNCLASSIFIED), or when a cancellation stops the run before reaching the parent. In the cancellation case the child should be SKIPPED with no reason, like the rest of the remainder.
  • Expected: a child is COVERED_BY_PARENT only when its parent was actually deleted. Otherwise it goes through its own checks and is deleted on its own. This has to be decided at run time, with descendants run after the selected folders that contain them. That is how the duplicate side does it now (4d52a52, FolderBulkDuplicateProcessor#process and #ancestorsFirst).

2. A request with no body gets a 500, not 400 EMPTY_SELECTION

FolderBulkDeleteHelper.submit reads form.assetPaths() with no null check (FolderBulkDeleteHelper.java:85), so POST /api/v1/assets/folders/_bulkdelete with no body throws a NullPointerException. A body of {} already gets 400 EMPTY_SELECTION. A missing form should be treated as an empty selection, as the duplicate side does since 4a49608.

3. Resolving each submitted path also lists the folder's whole contents

The processor turns each path into a folder with WebAssetHelper.getAssetInfo, which also runs a browser query over the folder's entire contents, only for the folder itself to be read afterwards. On large folders this is repeated work for up to the maximum number of paths, before the run's heartbeat starts. Resolving with AssetPathResolver alone finds the same site and folder, and raises the same exceptions the PATH_NOT_FOUND mapping relies on. That is how the duplicate side does it since 4da0ebe.

Acceptance criteria for these three

  • A child under a parent that was refused, failed or never reached is not reported COVERED_BY_PARENT, with an integration test for each case.
  • A bulk delete request with no body answers 400 EMPTY_SELECTION, with a unit test and a Postman request.
  • Submitted paths are resolved without listing the folders' contents. A path naming a file, with or without a trailing slash, is still PATH_NOT_FOUND.

Activity

  1. added theissue type on Sep 28, 2026
  2. changed the title [-]Folder delete that fails part-way permanently deletes the binaries of files it already walked, while reporting that nothing was deleted[/-] [+]Folder delete: a failure part-way loses the binaries it already walked, plus three smaller bulk delete defects[/+] on Sep 29, 2026
  3. assigned and unassigned on Sep 29, 2026
  4. self-assigned this
    on Oct 1, 2026
  5. self-assigned this
    on Oct 9, 2026
  6. 6 remaining items

  7. claude commented on Oct 13, 2026

    @claude
    Contributor

    🧪 Post-Merge Test Plan

    Source PR: #38000
    Related issues: #37782

    Ownership and status

    Responsibility Developer Status
    Plan Reviewer — developer who implemented the fix @zJaaal Pending Review
    Test Executor — independent developer TBD Not Started

    The Plan Reviewer must validate scope, correctness, missing cases, and possible hallucinations
    before execution begins.

    This is a living test plan. The Plan Reviewer and Test Executor may add relevant test cases.
    Every added case must follow the existing format and receive a final result.

    Test summary

    Test Case Number Scenario Result Notes
    TC-001 Successful folder delete (single and bulk) still clears files, cache and metadata Not Run Yet
    TC-002 Refused or locked folder delete loses no files already reached (#37782 core defect) Not Run Yet
    TC-003 Bulk delete no longer reports an undeleted descendant as COVERED_BY_PARENT Not Run Yet
    TC-004 Push-publish receiver rewrite shortly after a destroy is unaffected by deferred removal Not Run Yet
    TC-005 Content type deletion still clears files and metadata for its content Not Run Yet
    View full test plan

    Summary

    PR #38000 fixes #37782: a folder delete that fails part-way through its tree left the files
    already walked permanently deleted from disk even though the database rolled back, because the
    binary and metadata removal ran immediately instead of inside the transaction. The fix defers
    that removal until the outermost transaction commits, and rolls it back with everything else when
    the delete fails. The same PR also carries three smaller bulk-delete defects from the same issue:
    a descendant wrongly reported COVERED_BY_PARENT when its ancestor was never actually deleted, a
    missing request body answering 500 instead of 400 EMPTY_SELECTION, and path resolution that
    listed the whole contents of a folder needlessly. Tests already added by the PR exercise nearly
    every acceptance criterion at the API and REST level (rollback keeps files for every destroy path,
    a successful delete still clears them, the empty-body 400, path resolution). This plan adds cases
    that are only verifiable by hand through the actual Content Drive and Workflow Center UI, or that
    the spec itself flags as a regression risk (the push-publish receiver). None of the cases below
    have been executed; every result is Not Run Yet.

    Test Cases

    - Test ID: TC-001
    - Issues: #37782
    - Test Name: Successful folder delete clears files, cache and metadata (single and bulk)
    - Risk: Critical
    - Scenario: Happy Path
    - Steps To Reproduce:
      1. As a user with full permissions, create folder /qa-happy/ with subfolder /qa-happy/sub/.
      2. Add a file asset test.txt (binary field) to /qa-happy/sub/; open it once in a context that
         generates a resized image, so a resized-image cache directory exists for it; confirm it
         opens at /qa-happy/sub/test.txt.
      3. In Content Drive, right-click /qa-happy/ and choose Delete Folder; confirm the UI reports
         success.
      4. Immediately after the success response, request /qa-happy/sub/test.txt and its dA path
         (/dA/<inode>/...).
      5. Repeat steps 1 and 2 with a new folder /qa-happy-bulk/ and its own file; in Content Drive
         select /qa-happy-bulk/ and delete it through Workflow Center, Delete (bulk delete); confirm
         the outcome reports SUCCESS.
      6. Immediately after the outcome is recorded, request the path of the bulk-deleted file.
    - Expected Result: In both the single-folder and bulk delete, as soon as success is reported the
      file path and its dA path return 404 right away, with no perceptible delay: the removal now
      runs after the transaction commits but still finishes synchronously before the caller sees
      success, so a successful delete clears the binary, its resized-image cache and its metadata
      exactly as it did before this fix.
    
    - Test ID: TC-002
    - Issues: #37782
    - Test Name: Refused or locked folder delete loses no files already reached
    - Risk: Critical
    - Scenario: Negative
    - Steps To Reproduce:
      1. Create a back-end user without the CMS Administrator role.
      2. Create folder /qa-bug/ with two subfolders /qa-bug/a/ and /qa-bug/b/ (a sorts before b, so
         it is walked first). Add a file asset test.txt to /qa-bug/a/; confirm it opens at
         /qa-bug/a/test.txt.
      3. Give the role of that user View, Edit, Edit Permissions and Publish on /qa-bug/, inherited
         by its children; then on /qa-bug/b/ only, remove Edit Permissions for that role (keep View,
         Edit, Publish).
      4. As that user, in Content Drive, right-click /qa-bug/ and choose Delete Folder. Confirm the
         delete is refused, citing missing edit permissions on /qa-bug/b/, then request
         /qa-bug/a/test.txt.
      5. Repeat steps 2 and 3 with a new folder /qa-bug-bulk/ (subfolders a/, b/); as the same
         restricted user, select /qa-bug-bulk/ in Content Drive and delete it through Workflow
         Center, Delete (bulk delete). Confirm the outcome reports /qa-bug-bulk/ as FAILED,
         PERMISSION_DENIED, then request /qa-bug-bulk/a/test.txt.
      6. Repeat once more with folder /qa-bug-lock/ (subfolders a/, b/) where the restricted user has
         full permissions on both; instead of removing a permission, have a second user check out
         and lock a content item inside /qa-bug-lock/b/ without publishing it, so the delete by the
         first user of /qa-bug-lock/ fails on the lock instead of a permission. Confirm
         /qa-bug-lock/a/test.txt still opens after the failed delete.
    - Expected Result: In every variant the delete is reported as failed, not success; every folder,
      subfolder, content item and file record is still listed in Content Drive exactly as before the
      attempt; and the file in the already-walked subfolder (a/) still opens by its path: no binary,
      resized-image cache or metadata is lost even though the delete did not complete.
    
    - Test ID: TC-003
    - Issues: #37782
    - Test Name: Bulk delete no longer reports an undeleted descendant as COVERED_BY_PARENT
    - Risk: High
    - Scenario: Negative
    - Steps To Reproduce:
      1. As a back-end user who may delete /qa-cov/parent/child/ but not /qa-cov/parent/ itself (for
         example, missing Edit Permissions on the parent only, inherited normally otherwise), create
         both folders if they do not already exist.
      2. In Content Drive, select both /qa-cov/parent/ and /qa-cov/parent/child/ and run Workflow
         Center, Delete (bulk delete) on the selection.
      3. Review the bulk delete outcome report for both paths.
    - Expected Result: /qa-cov/parent/ is reported FAILED (for example PERMISSION_DENIED).
      /qa-cov/parent/child/ is reported SUCCESS or FAILED on its own merits, never SKIPPED or
      COVERED_BY_PARENT, since the parent was never actually deleted. If /qa-cov/parent/child/ came
      back SUCCESS, it no longer appears in Content Drive.
    
    - Test ID: TC-004
    - Issues: #37782
    - Test Name: Push-publish receiver rewrite after a destroy is unaffected by the deferred removal
    - Risk: High
    - Scenario: Edge
    - Steps To Reproduce:
      1. Using an existing push-publish sender and receiver pair, on the sender create a file asset
         with a binary field, publish it to the receiver, and confirm it opens on the receiver.
      2. On the sender, delete (destroy) that file asset.
      3. Immediately after, on the sender publish an updated version of the same content so the
         push-publish bundle on the receiver reuses the same identifier and inode pattern as the
         content just destroyed, and push it to the receiver right after the destroy.
      4. On the receiver, request the new asset file as soon as the second push publish completes.
    - Expected Result: The newly push-published file is served correctly on the receiver, with no
      missing binary and no leftover from the destroyed version: the after-commit removal from the
      destroy does not race with, or clobber, the newer file written to the same inode on the
      receiver.
    
    - Test ID: TC-005
    - Issues: #37782
    - Test Name: Content type deletion still clears files and metadata for its content
    - Risk: Medium
    - Scenario: Edge
    - Steps To Reproduce:
      1. Create a content type with a binary field; add two content items using it, each with a
         file; confirm both open by path.
      2. Delete the content type (Content Types, the type, Actions, Delete), confirming the content
         type and its content items are removed.
      3. Immediately after the delete finishes, request the file path of each former content item
         and its dA path.
    - Expected Result: Both requests return 404 as soon as the content type delete finishes: the
      binaries and metadata of the content are gone even though, by the time the removal runs, the
      content type itself no longer exists.
    
  8. removed their assignment
    on Oct 13, 2026
  9. moved this from In Review to QA in dotCMS - Product Planningon Oct 13, 2026
  10. rjvelazco commented on Oct 14, 2026

    @rjvelazco
    Member

    Passed QA

    • dotCMS Docker Image: [dotcms/dotcms:turnk_c711383]

    Video

    video.mov
    video-2.mov
    video-3.mov
  11. removed theissue type on Oct 15, 2026
  12. added theissue type on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions