Review main Merged

90948[TASK] Improve ResourceStorage->getUniqueName() to reduce collisions

Alexander Schnitzler CR +2 V +2 Easy +15 −6 updated 10/10/25, 20:37

Commit message

Previously, getUniqueName() would try to generate a unique file name
inside a folder by appending _01 to _99 to the base name. If all
variants were taken, it would attempt a single random string. If that
random name was also in use, an exception was thrown.

Although rare, such exceptions occurred.

This change makes ResourceStorage try up to 99 random strings after
exhausting the _01-_99 suffixes, greatly reducing the chance of
collision and effectively eliminating the exception.

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Markus Klein +1
    • Christian Kuhn +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Christian Kuhn +1
    • core-ci +1 CI

Issues 1

Files 1

Review log 1518

  1. Alexander Schnitzler uploaded patch set 1 10/07/25, 15:20

  2. core-ci voted on patch set 1 V +1 10/07/25, 15:28 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86169

  3. Alexander Schnitzler uploaded patch set 2 V +1 10/07/25, 15:45

  4. Alexander Schnitzler wrote 10/07/25, 15:46

    Topic set to FAL
  5. core-ci voted on patch set 2 V +1 10/07/25, 15:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86171

  6. Alexander Schnitzler marked it ready for review 10/07/25, 15:52

  7. Alexander Schnitzler uploaded patch set 3 V +1 10/07/25, 16:00

  8. core-ci voted on patch set 3 V +1 10/07/25, 16:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86172

  9. Garvin Hicking commented on patch set 3 10/07/25, 16:45

    ResourceStorage.php:2577

    I wonder if instead using this "again! again! again!" logic that possible wrecks your file I/O lookups in case of remote file systems, why not cut this short and use an easy hashing algo after like the third try or so, and append that? Two tries may be for a "sensible" counter might be acceptable before a long filename kicks in?
  10. Alexander Schnitzler commented on patch set 3 10/07/25, 17:38

    ResourceStorage.php:2577 Reply

    I wonder if you intentionally commented at this place. This fallback method is actually less I/O heavy than the 99 checks for file names _01-_99. Hitting a used file name here more than once is close to impossible. So, yes, we could cut this part short and just try 3 times but the tries are actually just an exit strategy for this loop in case weird things on the driver are happening. Any real world scenario will have a unique file name at the first or second try. I am happy to discuss the earlier approach though. To me, appending 01-99 doesn't bring any benefit at all. Maybe someone has some insights here. If it were up to me, I would skip that part and use slightly longer random string. Starting with 8 characters, it's completely unlikely to hit a used file name. With 10 even more. We could also leverage Random:generateRandomHexString for that btw but I kept this patch conservative to be able to backport if this can be considered a bugfix.
  11. Garvin Hicking commented on patch set 3 10/07/25, 18:06

    ResourceStorage.php:2577 Reply

    I meant the general approach. Each time I stumbled across it I wondered if we should keep it. Personally I'd embrace the chance to add a "slightly longer random string", yes. I'm sorry that came across offending your patch, that was not my intention. Happy for other feedbsck/input. Mine is definitely not blocking.
  12. Alexander Schnitzler commented on patch set 3 10/07/25, 19:57

    ResourceStorage.php:2577 Reply

    Don’t worry. Nothing’s offensive here. Just wanted to make sure I understand your comment better.
  13. Christian Kuhn voted on patch set 3 CR +1 V +1 10/08/25, 22:56

  14. Markus Klein commented on patch set 3 10/09/25, 05:54

    why not v13 as well?
  15. Alexander Schnitzler commented on patch set 3 10/09/25, 06:16

    Reply

    I learnt that patches that are too specific are often argued about unnecessarily and it's better to have a more open first approach to let the patch develop in one way or the other. One undiscussed proposal is to remove the 01-09 suffix altogether and I want to leave the argument, whether that's breaking, to others. The patch, as is, can be ported to 13 IMHO.
  16. Markus Klein commented on patch set 3 CR +1 10/09/25, 12:39

    Reply

    Thanks, for the info. I was more curious if something speaks against having this in the stable version too.
  17. Stefan Bürk voted on patch set 3 CR +2 V +2 10/10/25, 20:37

  18. Stefan Bürk merged patch set 4 10/10/25, 20:37