Problem/Motivation
When a media type is set to Download and sync assets, and the asset filename from the DAM has changed since the asset was last synced to Drupal, when the sync runs the new file is downloaded, and the existing file entity is updated, but the old file remains on the filesystem (and is no longer associated with a Drupal file entity).
Steps to reproduce
- Configure a media type to Download and sync assets
- Sync an asset of that media type to Drupal, noting the file name
- Upload a new version of the file to the DAM, using a different file name
- Re-sync the asset
- In the Drupal file listing (
/admin/content/files), you will see the same file entity updated with the new file name - Examining the filesystem directly, you will see both the old file and the new file
This case should be handled in \Drupal\acquia_dam\AssetFileEntityHelper::updateExistingFile().
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | acquia_dam-3569995-3-files-not-cleaned-up.patch | 1.02 KB | becw |
Issue fork acquia_dam-3569995
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
becw commentedI originally reported this issue in acquia_dam 1.1.7, and half of the issue is still present as of acquia_dam 1.1.14.
Previously, both the new file and the old file remained both on the filesystem and as a Drupal file entity. Now, the existing Drupal file entity is updated with the new file, but the old file is still present on the filesystem (and no longer linked to a Drupal file entity).
I've updated the issue description to reflect the behavior as of acquia_dam 1.1.14.
Comment #3
becw commentedI've attached a patch that fixes the issue in my testing.
Comment #6
rajeshreeputraAssetFileEntityHelper changes:
Modified
updateExistingFile()to delete all files in the directory before writing the new file, using newdeleteDirectoryContents()helper handles the directory cleanup with a\UnexpectedValueExceptioncatch for the edge cases if any like directory does not present.This not only handles the filename-change orphan scenario but also cleans up any pre-existing orphaned files from before this fix was deployed.
Code coverage:
New test
testAssetFileReDownloadFilenameChange()inMediaIntegrationTest:a56fb261-8ad5-4e0d-8323-0e8a3659ed38with old versioned84ab8e-a822-471d-b2f4-21b7353e4d0c(filenamebobsCarsAgileExercisesOld.pdf) and new versione37312f5-e761-4ec4-92f2-8f0407f57bc7(filenamebobsCarsAgileExercisesNew.pdf)downloadFile,updateExistingFile, anddeleteDirectoryContentsComment #8
rajeshreeputraMR merged!