Commit 2dcb076
committed
minor symfony#60808 [HttpFoundation] Handle error when expected directory is a file (afiestas)
This PR was merged into the 7.4 branch.
Discussion
----------
[HttpFoundation] Handle error when expected directory is a file
| Q | A
| ------------- | ---
| Branch? | 7.4
| Bug fix? | kinda
| New feature? | no
| Deprecations? | no
| License | MIT
[HttpFoundation] In File::getTargetFile the directory is recursively created if it does not exists. If directory creation fails a FileException is thrown.
This commit improves error clarity by adding a new FileException for the relatively common case where the path exists but instead of a directory it is a file.
Since errors from `@mkdir` are being suppressed we don't really know why the operation has failed.
There are many ways of doing this depending on the warranties that Symfony gives on retro-compatibility for the thrown exceptions. I Haven't been able to find documentation about that so I've decided to open a PR with the easiest to read change to get the conversation started.
Depending on your preferences we could:
- Manage the mkdir errors similar to how is done in [Filesystem::box](https://github.com/symfony/filesystem/blob/7.3/Filesystem.php#L753). Perhaps add that extra information after the current message like "Unable to create the %s directory (error goes here).
- Same thing as the PR but as part of the if/elseif block.
- Move the is_file check within the error handling code path to prevent another I/O operation (so we do not affect the happy path)
- Others?
Also since I haven't been able to find the compatibility guidelines I'm doing this to the 7.4 branch.
Commits
-------
b1a9d58 [HttpFoundation] Handle error when directory is a file1 file changed
+4
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
118 | | - | |
119 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
120 | 120 | | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
0 commit comments