Skip to content

#240 - Fix FileMoverTask: autoincrement applied to the whole path - #248

Merged
njoubert-cleverage merged 2 commits into
mainfrom
240
Oct 9, 2026
Merged

njoubert-cleverage merged 2 commits into
mainfrom
240

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #240.

With autoincrement: true, FileMoverTask::makeFilenameUnique() applied its regex /^(.*?)(-\d+)?(\.[^.]*)$/ to the whole destination path:

  1. a dot in a directory name was taken as the extension: repro.d/dest/file gave repro-1.d/dest/file and the move failed with an IOException;
  2. a -<digits> ending of the file name was taken as a previous increment and replaced: report-2024.csv gave report-1.csv;
  3. also found while fixing: with no dot in the path, the fallback appended to the previous attempt (file-1-1 instead of file-2 when file and file-1 exist), and a hidden file .env gave -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 of pathinfo(), which handles .env as an extension, and the directory part is kept as given instead of dirname(), which would turn a relative file.csv into ./file-1.csv.

Documentation: autoincrement description and a note with examples in docs/reference/tasks/file_mover_task.md. Tests in FileMoverTaskTest, with a dotted temporary directory: file.csv, file, report-2024.csv, archive.tar.gz, .env, .env.local, and an existing file-1 (4 of them fail on main).

PHPUnit (808 tests), PHPStan, PHP-CS-Fixer and Rector pass, and the changed files are valid PHP 8.2.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

Generated names change with autoincrement (minor):

  • a file name ending with -<digits> keeps it: report-2024-1.csv instead of report-1.csv;
  • a hidden file: .env-1 instead of -1.env;
  • a file without extension when file-1 exists: file-2 instead of file-1-1.

A file without extension in a dotted directory used to fail, it is now moved.

🤖 Generated with Claude Code

njoubert-cleverage and others added 2 commits October 9, 2026 10:47
…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>
@njoubert-cleverage
njoubert-cleverage merged commit 4be0fa9 into main Oct 9, 2026
17 checks passed
@njoubert-cleverage
njoubert-cleverage deleted the 240 branch October 9, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileMoverTask: autoincrement applies to the whole path (dot in a directory name, numeric suffix in the file name)

1 participant