From 75414134803bc6fd9e433288f138a269044bdaec Mon Sep 17 00:00:00 2001 From: "Steven M. Cohen" Date: Sun, 22 May 2005 18:48:42 +0000 Subject: [PATCH] Add new timestampGranularity attribute to account for the typical case in PUT operations where the client is HH:mm:ss and the ftp server is HH:mm. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278325 13f79535-47bb-0310-9956-ffa450edef68 --- .../testcases/taskdefs/optional/net/ftp.xml | 5 +- .../tools/ant/taskdefs/optional/net/FTP.java | 60 +++++++++++++++++-- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/etc/testcases/taskdefs/optional/net/ftp.xml b/src/etc/testcases/taskdefs/optional/net/ftp.xml index a0c599a65..5603ce7a8 100644 --- a/src/etc/testcases/taskdefs/optional/net/ftp.xml +++ b/src/etc/testcases/taskdefs/optional/net/ftp.xml @@ -142,10 +142,10 @@ - + - + @@ -156,7 +156,6 @@ password="${ftp.password}" separator="${ftp.filesep}" remotedir="${tmp.remote}" - timediffmillis="${server.timestamp.granularity.millis}" newer="true" serverTimeZoneConfig="${ftp.server.timezone}" > diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java index 30c4103ff..68bca232d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java @@ -81,6 +81,11 @@ public class FTP protected static final int RM_DIR = 6; /** return code of ftp - not implemented in commons-net version 1.0 */ private static final int CODE_521 = 521; + + /** adjust uptodate calculations where server timestamps are HH:mm and client's + * are HH:mm:ss */ + private static final long GRANULARITY_MINUTE = 60000L; + /** Default port for FTP */ public static final int DEFAULT_FTP_PORT = 21; @@ -115,6 +120,8 @@ public class FTP private String serverLanguageCodeConfig = null; private String serverTimeZoneConfig = null; private String shortMonthNamesConfig = null; + private String timestampGranularity = null; + private long serverTimestampGranularity = 0L; private boolean isConfigurationSet = false; protected static final String[] ACTION_STRS = { @@ -1386,6 +1393,21 @@ public class FTP String getShortMonthNamesConfig() { return shortMonthNamesConfig; } + /** + * @return Returns the timestampGranularity. + */ + String getTimestampGranularity() { + return timestampGranularity; + } + /** + * @param timestampGranularity The timestampGranularity to set. + */ + public void setTimestampGranularity(String timestampGranularity) { + if (null == timestampGranularity || "".equals(timestampGranularity)) { + return; + } + this.timestampGranularity = timestampGranularity; + } /** * Checks to see that all required parameters are set. * @@ -1493,7 +1515,32 @@ public class FTP for (int i = dsfiles.length - 1; i >= 0; i--) { rmDir(ftp, dsfiles[i]); } - } else { + } else { + if (this.newerOnly) { + if (action == SEND_FILES) { + if ("NONE".equalsIgnoreCase(this.timestampGranularity)) + { + this.serverTimestampGranularity = 0L; + } + else if ("MINUTE".equalsIgnoreCase(this.timestampGranularity)) + { + this.serverTimestampGranularity = GRANULARITY_MINUTE; + } + else + { + this.serverTimestampGranularity = GRANULARITY_MINUTE; + } + } else if (action == GET_FILES) { + if ("MINUTE".equalsIgnoreCase(this.timestampGranularity)) + { + this.serverTimestampGranularity = GRANULARITY_MINUTE; + } + else + { + this.serverTimestampGranularity = 0L; + } + } + } for (int i = 0; i < dsfiles.length; i++) { switch (action) { case SEND_FILES: @@ -1749,11 +1796,16 @@ public class FTP long remoteTimestamp = files[0].getTimestamp().getTime().getTime(); long localTimestamp = localFile.lastModified(); - if (this.action == SEND_FILES) { - return remoteTimestamp + timeDiffMillis >= localTimestamp; + return remoteTimestamp + + this.timeDiffMillis + + this.serverTimestampGranularity + >= localTimestamp; } else { - return localTimestamp >= remoteTimestamp + timeDiffMillis; + return localTimestamp + >= remoteTimestamp + + this.timeDiffMillis + + this.serverTimestampGranularity; } }