DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=29468>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=29468 [vfs] setLastModified patch for sftp Summary: [vfs] setLastModified patch for sftp Product: Commons Version: unspecified Platform: All OS/Version: All Status: NEW Severity: Enhancement Priority: Other Component: Sandbox AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] 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){ throw new SftpException(SSH_FX_FAILURE, ""); } buf.getInt(); i=buf.getInt(); if(i!=SSH_FX_OK){ throwStatusError(buf, i); } } catch(Exception e){ if(e instanceof SftpException) throw (SftpException)e; throw new SftpException(SSH_FX_FAILURE, ""); } } 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 + * [EMAIL PROTECTED] #doGetType} does not return [EMAIL PROTECTED] 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 + { + // this was the only way to make the long to int preserving accuracy + String str = "" + modtime; + int newMTime = Integer.parseInt(str.substring(0, str.length() - 3)); + channel.setMTime(getName().getPath(), newMTime, attrs); + } + finally + { + fileSystem.putChannel(channel); + } + } + } + + /** * 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 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
