mirror of https://github.com/apache/nifi.git
NIFI-13159 Moved Remote Delete after Put for PutFTP/PutSFTP REPLACE Strategy
This closes #8914 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
b5b61d960c
commit
3c7b262619
|
@ -225,7 +225,6 @@ public abstract class PutFileTransfer<T extends FileTransfer> extends AbstractPr
|
|||
logger.warn("Resolving conflict by rejecting {} due to conflicting filename with a directory or file already on remote server", flowFile);
|
||||
break;
|
||||
case FileTransfer.CONFLICT_RESOLUTION_REPLACE:
|
||||
transfer.deleteFile(flowFile, path, fileName);
|
||||
destinationRelationship = REL_SUCCESS;
|
||||
transferFile = true;
|
||||
penalizeFile = false;
|
||||
|
|
|
@ -475,6 +475,13 @@ public class FTPTransfer implements FileTransfer {
|
|||
}
|
||||
|
||||
if (!filename.equals(tempFilename)) {
|
||||
try {
|
||||
// file was transferred to a temporary filename, attempt to delete destination filename before rename
|
||||
client.deleteFile(fullPath);
|
||||
} catch (final IOException e) {
|
||||
logger.debug("Failed to remove {} before renaming temporary file", fullPath, e);
|
||||
}
|
||||
|
||||
try {
|
||||
logger.debug("Renaming remote path from {} to {} for {}", tempFilename, filename, flowFile);
|
||||
final boolean renameSuccessful = client.rename(tempFilename, filename);
|
||||
|
|
|
@ -785,6 +785,13 @@ public class SFTPTransfer implements FileTransfer {
|
|||
}
|
||||
|
||||
if (!filename.equals(tempFilename)) {
|
||||
try {
|
||||
// file was transferred to a temporary filename, attempt to delete destination filename before rename
|
||||
sftpClient.rm(fullPath);
|
||||
} catch (final SFTPException e) {
|
||||
logger.debug("Failed to remove {} before renaming temporary file", fullPath, e);
|
||||
}
|
||||
|
||||
try {
|
||||
sftpClient.rename(tempPath, fullPath);
|
||||
} catch (final SFTPException e) {
|
||||
|
|
|
@ -642,27 +642,6 @@ public class TestServerSFTPTransfer {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutWhenFileAlreadyExists() throws IOException {
|
||||
final String permissions = "rw-rw-rw-";
|
||||
|
||||
final Map<PropertyDescriptor, String> properties = createBaseProperties();
|
||||
properties.put(SFTPTransfer.PERMISSIONS, permissions);
|
||||
|
||||
final String fileContent = "this is a test";
|
||||
|
||||
try (final SFTPTransfer transfer = createSFTPTransfer(properties);
|
||||
final InputStream in = new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8))) {
|
||||
|
||||
// Verify file already exists
|
||||
final FileInfo fileInfoBefore = transfer.getRemoteFileInfo(null, DIR_2, FILE_1);
|
||||
assertNotNull(fileInfoBefore);
|
||||
|
||||
// Should fail because file already exists
|
||||
assertThrows(IOException.class, () -> transfer.put(null, DIR_2, FILE_1, in));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutWhenDirectoryDoesNotExist() throws IOException {
|
||||
final String permissions = "rw-rw-rw-";
|
||||
|
|
Loading…
Reference in New Issue