Skip to content

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

Closed

Description

@njoubert-cleverage

Description

With autoincrement: true, FileMoverTask::makeFilenameUnique() applies its regex /^(.*?)(-\d+)?(\.[^.]*)$/ to the whole path instead of the file name:

  1. File without extension, directory containing a dot: the "extension" is taken in the directory name, and the task tries to move the file into a directory that does not exist.
  2. File name ending with a numeric suffix: the suffix is considered as a previous increment and replaced: report-2024.csv becomes report-1.csv (part of the name is lost, and it may collide with another file).

Reproduction

move:
    service: '@CleverAge\ProcessBundle\Task\File\FileMoverTask'
    options:
        destination: '/tmp/repro.d/dest'
        autoincrement: true
  1. Input /tmp/repro.d/src/file, with /tmp/repro.d/dest/file already existing:

    Symfony\Component\Filesystem\Exception\IOException: Cannot rename "/tmp/repro.d/src/file" to "/tmp/repro-1.d/dest/file": rename(...): No such file or directory
    

    Expected: the file is moved to /tmp/repro.d/dest/file-1.

  2. Input /tmp/repro.d/src/report-2024.csv, with /tmp/repro.d/dest/report-2024.csv already existing: the output is /tmp/repro.d/dest/report-1.csv.

    Expected: /tmp/repro.d/dest/report-2024-1.csv.

Reproduced on main (ad31c1f), PHP 8.5, Symfony 8.1, by calling the task / transformer directly. Found while adding the missing tests of #197.

Proposed fix

Apply the increment on the base name only (pathinfo() / dirname()), and always append -N to the original name (name-1.ext, name-2.ext...) instead of replacing an existing numeric suffix. Update file_mover_task.md, add tests.

Requirements

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

Breaking changes

Case 1 currently fails. Case 2 changes the generated name of files whose name ends with -<digits> (report-2024-1.csv instead of report-1.csv).

Activity

  1. added a commit that references this issue on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions