silverstripe / silverstripe-assets

Silverstripe Assets component
BSD 3-Clause "New" or "Revised" License
9 stars 66 forks source link

No prevention of duplicated file names when moving a file to a new folder #512

Closed sb-relaxt-at closed 1 year ago

sb-relaxt-at commented 2 years ago

I have encountered the following issue (tested in 1.10 but should be the same in 1.11):

  1. Create a folder "foo"
  2. Upload a file a.jpg to assets (id 2)
  3. Upload a different file a.jpg to assets/foo (id 3)
  4. Move the file from assets/a.jpg to assets/foo/a.jpg (for example via setting a new parent in the user interface)

As long as both files are not published everything is fine (as they have different hashes), but as soon as the files get published it will no longer work and one of the files will be overwritten. We will have the following db entries, whereas only one will generate a working URL:

In the filesystem only "foo/a.jpg" exists.

If both files do have the same content it is almost the same, but both files will generate a working URL.

From my understanding the file name should be also made unique if the ParentID has changed, adding a condition in File#onBeforeWrite.

Acceptance criteria

Note

PRs

maxime-rainville commented 1 year ago

Validated this.

It looks like if you drag tho folder around with the mouse, assets is smart enough to rename the file for you.

However, if you do it via the "Location" dropdown, you end up wit two files with the same name.

sb-relaxt-at commented 1 year ago

Thank you for looking into it, I almost forgot about it…

GuySartorelli commented 1 year ago

PR tagged. This will be automatically tagged when CI has finished running on the branch.