Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ public void onTrigger(ProcessContext context, ProcessSession session) throws Pro
filename = context.getProperty(FILENAME).evaluateAttributeExpressions(flowFile).getValue();
final Path filePath = directoryPath.resolve(filename).normalize();

if (!directoryPath.equals(filePath.getParent())) {
final Path fileParent = filePath.getParent();
if (!directoryPath.equals(fileParent == null ? Paths.get("") : fileParent)) {
final String errorMessage = "Attempting to delete file at path '%s' which is not a direct child of the directory '%s'"
.formatted(filePath, directoryPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ void sendsFlowFileToSuccessWhenDeletingADirectoryAndDirectoryIsEmpty() throws IO
runner.assertAllFlowFilesTransferred(DeleteSFTP.REL_SUCCESS);
}

@Test
void deletesFileWhenDirectoryPathIsDot() throws IOException {
final Path fileToDelete = Files.writeString(sshServerRootPath.resolve("test.txt"), "some text");
enqueue(".", fileToDelete.getFileName().toString());
assertExists(fileToDelete);

runner.run();

assertNotExists(fileToDelete);
runner.assertAllFlowFilesTransferred(DeleteSFTP.REL_SUCCESS, 1);
}

@Test
void sendsFlowFileToFailureWhenFileIsNotADirectChildOfTheDirectory() throws IOException {
final Path directoryPath = Files.createDirectories(sshServerRootPath.resolve("rel/path"));
Expand Down
Loading