Browse Source

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
master
Steven M. Cohen 20 years ago
parent
commit
7541413480
2 changed files with 58 additions and 7 deletions
  1. +2
    -3
      src/etc/testcases/taskdefs/optional/net/ftp.xml
  2. +56
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java

+ 2
- 3
src/etc/testcases/taskdefs/optional/net/ftp.xml View File

@@ -142,10 +142,10 @@


<target name="timed.test.put.older"> <target name="timed.test.put.older">
<tstamp> <tstamp>
<format property="five.minutes.older" pattern="${tstamp.format}" offset="-5" unit="minute"/>
<format property="one.minute.older" pattern="${tstamp.format}" offset="-60" unit="second"/>
</tstamp> </tstamp>


<touch datetime="${five.minutes.older}" pattern="${tstamp.format}" verbose="true">
<touch datetime="${one.minute.older}" pattern="${tstamp.format}" verbose="true">
<fileset dir="${tmp.remote}"> <fileset dir="${tmp.remote}">
<include name="A.timed"/> <include name="A.timed"/>
</fileset> </fileset>
@@ -156,7 +156,6 @@
password="${ftp.password}" password="${ftp.password}"
separator="${ftp.filesep}" separator="${ftp.filesep}"
remotedir="${tmp.remote}" remotedir="${tmp.remote}"
timediffmillis="${server.timestamp.granularity.millis}"
newer="true" newer="true"
serverTimeZoneConfig="${ftp.server.timezone}" serverTimeZoneConfig="${ftp.server.timezone}"
> >


+ 56
- 4
src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java View File

@@ -81,6 +81,11 @@ public class FTP
protected static final int RM_DIR = 6; protected static final int RM_DIR = 6;
/** return code of ftp - not implemented in commons-net version 1.0 */ /** return code of ftp - not implemented in commons-net version 1.0 */
private static final int CODE_521 = 521; 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 */ /** Default port for FTP */
public static final int DEFAULT_FTP_PORT = 21; public static final int DEFAULT_FTP_PORT = 21;


@@ -115,6 +120,8 @@ public class FTP
private String serverLanguageCodeConfig = null; private String serverLanguageCodeConfig = null;
private String serverTimeZoneConfig = null; private String serverTimeZoneConfig = null;
private String shortMonthNamesConfig = null; private String shortMonthNamesConfig = null;
private String timestampGranularity = null;
private long serverTimestampGranularity = 0L;
private boolean isConfigurationSet = false; private boolean isConfigurationSet = false;


protected static final String[] ACTION_STRS = { protected static final String[] ACTION_STRS = {
@@ -1386,6 +1393,21 @@ public class FTP
String getShortMonthNamesConfig() { String getShortMonthNamesConfig() {
return shortMonthNamesConfig; 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. * 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--) { for (int i = dsfiles.length - 1; i >= 0; i--) {
rmDir(ftp, dsfiles[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++) { for (int i = 0; i < dsfiles.length; i++) {
switch (action) { switch (action) {
case SEND_FILES: case SEND_FILES:
@@ -1749,11 +1796,16 @@ public class FTP


long remoteTimestamp = files[0].getTimestamp().getTime().getTime(); long remoteTimestamp = files[0].getTimestamp().getTime().getTime();
long localTimestamp = localFile.lastModified(); long localTimestamp = localFile.lastModified();

if (this.action == SEND_FILES) { if (this.action == SEND_FILES) {
return remoteTimestamp + timeDiffMillis >= localTimestamp;
return remoteTimestamp
+ this.timeDiffMillis
+ this.serverTimestampGranularity
>= localTimestamp;
} else { } else {
return localTimestamp >= remoteTimestamp + timeDiffMillis;
return localTimestamp
>= remoteTimestamp
+ this.timeDiffMillis
+ this.serverTimestampGranularity;
} }
} }




Loading…
Cancel
Save