diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeleteSFTP.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeleteSFTP.java index 5d284d3437c6..29b6845b7bbc 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeleteSFTP.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeleteSFTP.java @@ -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); diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeleteSFTP.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeleteSFTP.java index eeb91b824754..0ce6c5b50cd3 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeleteSFTP.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeleteSFTP.java @@ -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"));