davsclaus opened a new pull request, #29855: URL: https://github.com/apache/camel/pull/29855
_Claude Code on behalf of Claus Ibsen (davsclaus)_ JIRA: https://issues.apache.org/jira/browse/CAMEL-26928 ## Problem The file component option `jailStartingDirectory` (enabled by default) keeps the producer and the consumer listing inside the starting directory, also when a path resolves through a symbolic link (CAMEL-25412). The consumer's post-processing move did not apply the same check. After an exchange completes (`move`, or the default `.camel` folder), before processing (`preMove`) or after a failure (`moveFailed`), `GenericFileProcessStrategySupport.renameFile` deletes an existing target file, creates the target's parent directories and renames the file onto the target. When the target path lies inside the starting directory but a directory on that path is a symbolic link that resolves elsewhere, the delete, the directory creation and the rename (including the copy fallback of `copyAndDeleteOnRenameFail` and `renameUsingCopy`) acted on the resolved location instead of a location inside the starting directory. ## Change - `GenericFileProcessStrategySupport.renameFile`: for the `file` component (`FileOperations`), check the target before the existing target is deleted, before its parent directories are created and before the rename. The remote file components are not changed. - `FileOperations`: new `jailMoveToStartingDirectory(File)`, sharing the check of the producer (`GenericFileHelper.isWithinDirectoryResolvingLinks`) with a message that fits a move. As for the producer, only a target that is lexically inside the starting directory is checked, so a target configured outside of it on purpose (such as `move=../archive/${file:onlyname}` or an absolute archive path) keeps working. - A refused move fails like any other failed move: the file stays where it is, and the error goes to the exception handler (`onCompletionExceptionHandler` for commit and rollback, the consumer's exception handler for `preMove`). - `jailStartingDirectory=false` keeps the previous behaviour. - `file-component.adoc` (section "Symbolic links and the starting directory") and the upgrade guides (4.24, and the 4.22.3 and 4.18.6 sections for the backports) describe the change; the catalog copy of the component doc is regenerated. ## Tests New `FileConsumerMoveJailStartingDirectorySymlinkTest` in `core/camel-core`, next to `FileConsumerJailStartingDirectorySymlinkTest` (skipped where symbolic links cannot be created): - the default `.camel` folder, `move`, `preMove` and `moveFailed` folders that are links resolving outside the starting directory are not used: the file outside keeps its content and the consumed file stays in place - the same with `recursive=true` (a sub directory's `.camel` folder) and with `renameUsingCopy=true` - a move folder that is a link resolving inside the starting directory is still used - `move=../archive/${file:onlyname}` (configured outside the starting directory) still works - `jailStartingDirectory=false` still moves through the link The six "is not used" tests fail without the change in `camel-file`; the other three pass with and without it. The existing `FileConsumerJailStartingDirectorySymlinkTest`, `FileProducerJailStartingDirectory*Test` and the other `org.apache.camel.component.file` tests of camel-core pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
