From 1ed80584e7568f1d60048f3aeb77896f22d08021 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Thu, 29 Jun 2006 21:18:15 +0000 Subject: [PATCH] Bug 149150 - fix timestamps for ssh, other file services to be done --- .../services/ssh/files/SftpFileService.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java index a9d27b4b297..50c0a19cec6 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java @@ -252,6 +252,19 @@ public class SftpFileService extends AbstractFileService implements IFileService channel=(ChannelSftp)fSessionProvider.getSession().openChannel("sftp"); //$NON-NLS-1$ channel.connect(); channel.put(localFile.getAbsolutePath(), dst, sftpMonitor, mode); //$NON-NLS-1$ + SftpATTRS attr = channel.stat(dst); + attr.setACMODTIME(attr.getATime(), (int)(localFile.lastModified()/1000)); + ////TODO check if we want to maintain permissions + //if (!localFile.canWrite()) { + // attr.setPERMISSIONS( attr.getPermissions() & (~00400)); + //} + channel.setStat(dst, attr); + if (attr.getSize() != localFile.length()) { + //Error: file truncated? - Inform the user!! + //TODO throw exception to show an error dialog! + System.err.println("ssh.upload: file size mismatch for "+dst); + return false; + } Activator.trace("SftpFileService.upload "+remoteFile+ " ok"); //$NON-NLS-1$ //$NON-NLS-1$ } catch (Exception e) { @@ -337,6 +350,17 @@ public class SftpFileService extends AbstractFileService implements IFileService channel=(ChannelSftp)fSessionProvider.getSession().openChannel("sftp"); //$NON-NLS-1$ channel.connect(); channel.get(remotePath, localFile.getAbsolutePath(), sftpMonitor, mode); //$NON-NLS-1$ + SftpATTRS attr = channel.stat(remotePath); + localFile.setLastModified(1000L * attr.getMTime()); + //TODO should we set the read-only status? + //if (0==(attrs.getPermissions() & 00400)) localFile.setReadOnly(); + if (attr.getSize() != localFile.length()) { + //Error: file truncated? - Inform the user!! + //TODO throw exception to show an error dialog! + System.err.println("ssh.download: file size mismatch for "+remotePath); + return false; + } + Activator.trace("SftpFileService.download "+remoteFile+ " ok"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Exception e) { @@ -346,10 +370,16 @@ public class SftpFileService extends AbstractFileService implements IFileService //e.printStackTrace(); //throw new RemoteFileIOException(e); Activator.trace("SftpFileService.download "+remoteFile+" failed: "+e.toString()); //$NON-NLS-1$ //$NON-NLS-2$ + //Note: In case of an exception, the caller needs to ensure that in case + //we downloaded to a temp file, the temp file is deleted again, or a + //broken incorrect file might be synchronized back to the source, thus + //destroying the original file!! return false; } finally { - if (channel!=null) channel.disconnect(); + if (channel!=null) { + channel.disconnect(); + } } return true; }