Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
None
-
Operating System: All
Platform: All
-
29468
Description
Here would be the doSetLastModifiedTime() method for SftpFileObject.
The reason it was left out in the first place was that one needed to
add a piece to jsch to make this happen.
Therefore I add here also a patched version of jsch-0.1.15 (as attachment) so
you can see that the patch compiles and works with the added source code of course.
So let's start with jsch.
The only addition was one method to com.jcraft.jsch.ChannelSftp
/**
- Sets the given attributes with the given mtime to a file denoted by the path
*/
public void setMTime(String path, int mtime, SftpATTRS attr) throws SftpException{
try{
attr.setACMODTIME(attr.getATime(), mtime);
sendSETSTAT(path.getBytes(), attr);
// Check for errors
buf.rewind();
int i=io.in.read(buf.buffer, 0, buf.buffer.length);
int length=buf.getInt();
int type=buf.getByte();
if(type!=SSH_FXP_STATUS)
buf.getInt();
i=buf.getInt();
if(i!=SSH_FX_OK)
}
catch(Exception e)
}
The nice side effect is that attr gets the new mtime and thus is uptodate with
the remote filesystem. Maybe we should in the case of error put the old mtime back.
By the way if anyone knows how to submit patches to jsch project that would be
greatly
appreciated, since it is not in cvs and there was an unanswered question about this
in jsch's discussion forum.
Then comes the patch to vfs to SftpFileObject
===================================================================
retrieving revision 1.9
diff -B -b -u -r1.9 SftpFileObject.java
@@ -147,6 +147,42 @@
}
/**
+ * Sets the last modified time of this file. Is only called if
+ *
does not return
{@link FileType#IMAGINARY}.
+ * <p/>
+ * Ignore folders because - I think - their Modified Time can not be set.
+ * Further I don't know exactly what the modified time of a folder means.
+ * The only reasonable interpretation I can come up with is that it is the
+ * latest of the modification times of it's children. And if it does not
+ * have children then it is equal to it's ctime (which in unix is change
+ * time and windows create time). But obviously this interpretation is not
+ * how it really is.
+ *
+ * @param modtime is modification time in milliseconds. SFTP protocol can
+ * send times with nanosecond precision but at the moment jsch send them
+ * with second precision.
+ */
+ protected void doSetLastModifiedTime(final long modtime)
+ throws Exception
+ {
+ if (getType() == FileType.FILE)
+ {
+ final ChannelSftp channel = fileSystem.getChannel();
+ try
+
+ finally
+
+ }
+ }
+
+ /**
- Deletes the file.
*/
protected void doDelete()
Here the problem was that jsch uses int for time values which we know is not a
very good idea.
Further SFTP version 5 says that they should be long values, but jsch implements
versions 0,1,2 and 3
so maybe it was int before. This string trick was the only way I could come up
with to keep
the int precise.
One thing I am wondering is that why is jzlib not part of vfs dependencies. And
could the compression be
easily enabled? If jzlib is not available
com/jcraft/jsch/jcraft/Compression.java is not compiled
with jsch. So if someone knows more about this, speak.
- Rami Ojares