Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Installations which have multiple web servers with non shared temporary directories can encounter a PDOException when attempting to replace a files in quick succession. The sequence required is the following:
- Choose to edit a file
- Upload a file with any name, called NAME1
- Choose to edit a file within the temporary file lifetime window, can be same as originally edited file or different file
- Upload a file called NAME1
- This is something not controllable by the user, but the uploaded file must be handled by a different server than the original upload. Specifically, the temporary directory can not have a file named NAME1 in it on the server handling the second upload
- PDOException happens. PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'temporary://test.pdf' for key 'uri': INSERT INTO {file_managed} (uid, filename, uri, filemime, filesize, status, timestamp, type) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7);
Proposed resolution
Insert a file_delete call after the file_unmanaged_copy call in file_entity_edit_submit
Remaining tasks
- Review patch
User interface changes
None
API changes
None
Original report by @tekante
Comment | File | Size | Author |
---|---|---|---|
#1 | file_entity-temporary_file_cleanup-2217315-1-D7.patch | 503 bytes | tekante |
Comments
Comment #1
tekante CreditAttribution: tekante commentedComment #2
Dave ReidThis is a duplicate of #2045611: Replacing a file leaves an unwanted temporary file that duplicates the replaced file