Repository navigation
#240 - Fix FileMoverTask: autoincrement applied to the whole path - #248
Merged
Merged
Conversation
…s computed on the whole path (a dot in a directory name was taken as the extension, making the move fail for a file without extension) and an existing numeric suffix of the file name was replaced (`report-2024.csv` became `report-1.csv`). The suffix is now appended to the file name only (`report-2024-1.csv`, `file-1`, `.env-1`). Update documentation, add tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #240.
With
autoincrement: true,FileMoverTask::makeFilenameUnique()applied its regex/^(.*?)(-\d+)?(\.[^.]*)$/to the whole destination path:repro.d/dest/filegaverepro-1.d/dest/fileand the move failed with anIOException;-<digits>ending of the file name was taken as a previous increment and replaced:report-2024.csvgavereport-1.csv;file-1-1instead offile-2whenfileandfile-1exist), and a hidden file.envgave-1.env.makeFilenameUnique()now splits the destination into directory / name / extension (on the last dot of the base name, a leading dot is not an extension) and builds<directory><name>-<i><extension>from the original name with the first free<i>.strrpos()is used instead ofpathinfo(), which handles.envas an extension, and the directory part is kept as given instead ofdirname(), which would turn a relativefile.csvinto./file-1.csv.Documentation:
autoincrementdescription and a note with examples indocs/reference/tasks/file_mover_task.md. Tests inFileMoverTaskTest, with a dotted temporary directory:file.csv,file,report-2024.csv,archive.tar.gz,.env,.env.local, and an existingfile-1(4 of them fail onmain).PHPUnit (808 tests), PHPStan, PHP-CS-Fixer and Rector pass, and the changed files are valid PHP 8.2.
Requirements
Breaking changes
Generated names change with
autoincrement(minor):-<digits>keeps it:report-2024-1.csvinstead ofreport-1.csv;.env-1instead of-1.env;file-1exists:file-2instead offile-1-1.A file without extension in a dotted directory used to fail, it is now moved.
🤖 Generated with Claude Code