Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A media with the same filename as an existing media overwrites existing file URI #251

Closed
mjordan opened this issue Mar 30, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@mjordan
Copy link
Owner

mjordan commented Mar 30, 2021

Media created via REST that have a filename that is already in use get assigned the same filename in Fedora and other Drupal filesystems. This can be seen in the database table below in the entries with fid 36 and 40. This is because REST bypasses the "File directory" settings in the media file configuration (as configured at e.g. admin/structure/media/manage/image/fields/media.image.field_media_image).

mysql> select fid,uuid,filename,uri from file_managed;
+-----+--------------------------------------+--------------------------+------------------------------------------+
| fid | uuid                                 | filename                 | uri                                      |
+-----+--------------------------------------+--------------------------+------------------------------------------+
|   1 | db2cad05-1e3b-4b35-b163-99d7d036130d | content_browser_icon.png | public://content_browser_icon.png        |
|   9 | 26702192-9776-4b08-89dd-4a467d046ad7 | generic.png              | public://media-icons/generic/generic.png |
|  36 | a4e0282a-07eb-40a9-bc0c-38aea0009fda | download.jpg             | fedora://download.jpg                    |
|  37 | 467877a1-935a-498b-8061-0243c1a31116 | 9-Service File.jpg       | public://2021-03/9-Service File.jpg      |
|  38 | c808ebe6-3d8a-4d9f-900d-0dceb58b00e4 | 9-Thumbnail Image.jpg    | public://2021-03/9-Thumbnail Image.jpg   |
|  39 | a3a2bf9a-bc7b-4073-8ab0-d481d7f1026a | 9-FITS File.xml          | public://2021-03/9-FITS File.xml         |
|  40 | 75f229f1-fa28-4b8a-9c76-3f92fdf5fcf5 | download.jpg             | fedora://download.jpg                    |
|  41 | 632aef5f-eac5-4004-830b-cc6c1727c480 | 10-Service File.jpg      | public://2021-03/10-Service File.jpg     |
|  42 | bcbee42f-90ae-4d7f-b75d-5d02bbe89cdb | 10-Thumbnail Image.jpg   | public://2021-03/10-Thumbnail Image.jpg  |
|  43 | c17e9f13-c6ee-4eac-b673-95d56fe4353e | 10-FITS File.xml         | public://2021-03/10-FITS File.xml        |
|  44 | 992ac9d7-80f3-4bb3-a85f-23375ee7d7a9 | download.jpg             | fedora://2021-03/download.jpg            |
|  45 | 943fbbf9-66cc-4a34-8e32-ca9a05611ef4 | 11-Service File.jpg      | public://2021-03/11-Service File.jpg     |
|  46 | a4db4a0c-9ee5-4f1c-b54b-a67dbd5aeb13 | 11-Thumbnail Image.jpg   | public://2021-03/11-Thumbnail Image.jpg  |
|  47 | eb7fe497-9595-4bf7-91b4-5c03f1cfd597 | 11-FITS File.xml         | public://2021-03/11-FITS File.xml        |
|  48 | d307056c-3bbb-4dde-8ea2-3ee5ef61d1a7 | download_0.jpg           | fedora://2021-03/download_0.jpg          |
|  49 | 3f0f0532-68e8-4fde-b09c-517f55b9e430 | 12-Service File.jpg      | public://2021-03/12-Service File.jpg     |
|  50 | bd211b64-50af-4a96-87a4-8d39e50f1e85 | 12-Thumbnail Image.jpg   | public://2021-03/12-Thumbnail Image.jpg  |
|  51 | 206e6305-55e1-4ac3-9900-d95a0d79549d | 12-FITS File.xml         | public://2021-03/12-FITS File.xml        |
+-----+--------------------------------------+--------------------------+------------------------------------------+
18 rows in set (0.00 sec)

As entries 44 and 48 show, when a media file is uploaded via the Drupal GUI, Drupal renames the file with a suffix (_0 in entry 48) in order to not make it overwrite the existing binary resource's URL in Fedora. URIs on the Drupal public filesystem are also overwritten, so this issue is not specific to Fedora.

@mjordan mjordan added the bug Something isn't working label Mar 30, 2021
@mjordan mjordan self-assigned this Mar 30, 2021
@mjordan mjordan changed the title A media with the same filename as an existing media overwrites the resource in Fedora A media with the same filename as an existing media overwrites existing file URI Mar 30, 2021
@mjordan
Copy link
Owner Author

mjordan commented Mar 30, 2021

In the short term, probably best to add a --check for duplicate filenames until a fix is available.

@mjordan
Copy link
Owner Author

mjordan commented Apr 18, 2021

For Drupal 9.2 and higher, resolved with b37f353. Still exists in earlier versions of Drupal. Warning added to docs.

@mjordan mjordan closed this as completed Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant