ravinarayansingh commented on code in PR #10405:
URL: https://github.com/apache/nifi/pull/10405#discussion_r2466997855
##########
nifi-extension-bundles/nifi-extension-utils/nifi-file-transfer/src/main/java/org/apache/nifi/processor/util/file/transfer/FetchFileTransfer.java:
##########
@@ -363,7 +383,39 @@ private void performCompletionStrategy(final FileTransfer
transfer, final Proces
transfer.ensureDirectoryExists(flowFile, new
File(absoluteTargetDirPath));
}
- final String destinationPath = String.format("%s/%s",
absoluteTargetDirPath, simpleFilename);
+ String destinationFileName = simpleFilename;
+ final FileInfo remoteFileInfo =
transfer.getRemoteFileInfo(flowFile, absoluteTargetDirPath,
destinationFileName);
+ if (remoteFileInfo != null) {
+ final String strategy =
context.getProperty(MOVE_CONFLICT_RESOLUTION).getValue();
+ switch (strategy.toUpperCase()) {
+ case FileTransfer.CONFLICT_RESOLUTION_REPLACE:
+ try {
+ transfer.deleteFile(flowFile,
absoluteTargetDirPath, destinationFileName);
+ } catch (final IOException deleteEx) {
+ getLogger().warn("Failed to delete existing
destination file {} on {}:{}. Move will be attempted regardless.",
+ destinationFileName, host, port,
deleteEx);
+ }
+ break;
+ case FileTransfer.CONFLICT_RESOLUTION_RENAME:
+ getLogger().info("Configured to RENAME on move
conflict for {}. A unique filename will be generated.", flowFile);
+ destinationFileName =
FileTransferConflictUtil.generateUniqueFilename(transfer,
absoluteTargetDirPath, destinationFileName, flowFile, getLogger());
+ break;
+ case FileTransfer.CONFLICT_RESOLUTION_IGNORE:
+ getLogger().debug("Configured to IGNORE move
conflict for {}. Original remote file will be left in place.", flowFile);
+ return;
+ case FileTransfer.CONFLICT_RESOLUTION_REJECT:
+ case FileTransfer.CONFLICT_RESOLUTION_FAIL:
+ getLogger().warn("Configured to {} on move
conflict for {}. Original remote file will be left in place.", strategy,
flowFile);
+ return;
Review Comment:
@exceptionfactory i have updated the code please have a look
--
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]