[
https://issues.apache.org/jira/browse/VFS-830?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17679305#comment-17679305
]
Gary D. Gregory commented on VFS-830:
-------------------------------------
If you can provide a PR I can review over the weekend, otherwise, it will be on
my back-back-burner.
> SFTP - moveto() throws FileSystemException: Could not set the last modified
> timestamp
> -------------------------------------------------------------------------------------
>
> Key: VFS-830
> URL: https://issues.apache.org/jira/browse/VFS-830
> Project: Commons VFS
> Issue Type: Bug
> Affects Versions: 2.9.0
> Environment: RHEL Linux server connecting to AWS Transfer SFTP Server
> Reporter: Simon Alexander
> Priority: Minor
>
> I am uploading a file via a temp file, by using the following code:
>
> {code:java}
> FileSystemOptions opts = createDefaultOptions();
> BytesIdentityInfo identityInfo = new BytesIdentityInfo(sshKey.getBytes(),
> null);
> SftpFileSystemConfigBuilder.getInstance().setIdentityProvider(opts,
> identityInfo);
> SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
> SftpFileSystemConfigBuilder.getInstance().setSessionTimeout(opts,
> Duration.ofMillis(10000));
> SftpFileSystemConfigBuilder.getInstance().setDisableDetectExecChannel(opts,
> true);
> // Create temp remote file object
> String tempFilePath = remoteFolder + FilePathSeparator + tempFileName;
> tempFileObject = remoteManager.resolveFile(new
> URI("sftp",server.getServerInfo(),server.HostName,server.Port,tempFilePath,null,null).toString(),
> opts);
> tempFileObject.copyFrom(sourceFileObject, Selectors.SELECT_SELF);
> // rename to the correct name
> tempFileObject.moveTo(remoteFileObject);} {code}
> In this code, `sourceFileObject` is on a remote linux server; and
> `tempFileObject` and `remoteFileObject` are on the AWS SFTP Transfer server.
> The exec channel is disabled on the server, so I've disabled its use here.
> When I run this code, the creation of the temp file runs successfully (using
> `copyFrom()`), but then the `moveTo()` call fails with the following
> exception:
> *java.io.IOException: copyFileBetweenServersUsingTempFile() - Could not set
> the last modified timestamp of "testRemoteFileName.txt"*
>
> I was trying to understand why the moveTo() call would fail in this way, so I
> started digging into the Apache code. As far as I can see, the call to
> `setLastModifiedTime()` only happens if the code thinks that the source and
> target filesystems are different - see [commons-vfs/AbstractFileObject.java
> at 83514069293cbf80644f1d47dd3eceaaf4e6954b · apache/commons-vfs ·
> GitHub|https://github.com/apache/commons-vfs/blob/83514069293cbf80644f1d47dd3eceaaf4e6954b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java#L1726]
> {code:java}
> if (fileSystem == newfile.getFileSystem()) // canRenameTo()
> {
> ...
> }
> else
> {
> ...
> destFile.getContent().setLastModifiedTime(this.getContent().getLastModifiedTime());
> } {code}
> The issue, I think, is the `==` in the canRenameTo() method - because I am
> actually moving from the temp file to the final file on the same file system,
> which means this should be returning true not false, right? presumably we
> should be using `.equals()` here, and overriding equals in the appropriate
> type of `FileSystem` object?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)