Author: sebb
Date: Sat Jan 17 23:13:51 2015
New Revision: 1652696
URL: http://svn.apache.org/r1652696
Log:
NET-566 UnixFTPEntryParser Drops Leading Spaces from File Names
Modified:
commons/proper/net/trunk/src/changes/changes.xml
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java
Modified: commons/proper/net/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1652696&r1=1652695&r2=1652696&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/net/trunk/src/changes/changes.xml [utf-8] Sat Jan 17
23:13:51 2015
@@ -68,6 +68,9 @@ This is mainly a bug-fix release. See fu
IMAPExportMbox (example app) allows IMAP folders to be exported into an mbox
file.
This is the inverse of the IMAPImportMbox example added previously
">
+ <action issue="NET-566" type="fix" dev="sebb" due-to="Gary
Russell">
+ UnixFTPEntryParser Drops Leading Spaces from File Names
+ </action>
<action type="update" dev="sebb">
examples/Main now uses a property file to define aliases instead
of scanning class files
</action>
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java?rev=1652696&r1=1652695&r2=1652696&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
Sat Jan 17 23:13:51 2015
@@ -145,6 +145,14 @@ public class FTPClientConfig
public static final String SYST_UNIX = "UNIX";
/**
+ * Identifier for alternate UNIX parser; same as {@link SYST_UNIX} but
leading spaces are
+ * trimmed from file names. This is to maintain backwards compatibility
with
+ * the original behaviour of the parser which ignored multiple spaces
between the date
+ * and the start of the file name.
+ */
+ public static final String SYST_UNIX_TRIM_LEADING = "UNIX_LTRIM";
+
+ /**
* Identifier by which a vms-based ftp server is known throughout
* the commons-net ftp system.
*/
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java?rev=1652696&r1=1652695&r2=1652696&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactory.java
Sat Jan 17 23:13:51 2015
@@ -124,7 +124,11 @@ public class DefaultFTPFileEntryParserFa
String ukey = key.toUpperCase(java.util.Locale.ENGLISH);
if (ukey.indexOf(FTPClientConfig.SYST_UNIX) >= 0)
{
- parser = new UnixFTPEntryParser(config);
+ parser = new UnixFTPEntryParser(config, false);
+ }
+ else if (ukey.indexOf(FTPClientConfig.SYST_UNIX_TRIM_LEADING) >= 0)
+ {
+ parser = new UnixFTPEntryParser(config, true);
}
else if (ukey.indexOf(FTPClientConfig.SYST_VMS) >= 0)
{
@@ -239,7 +243,8 @@ public class DefaultFTPFileEntryParserFa
return new CompositeFileEntryParser(new FTPFileEntryParser[]
{
new NTFTPEntryParser(config),
- new UnixFTPEntryParser(config)
+ new UnixFTPEntryParser(config,
+ config != null &&
FTPClientConfig.SYST_UNIX_TRIM_LEADING.equals(config.getServerSystemKey()))
});
}
}
@@ -271,7 +276,8 @@ public class DefaultFTPFileEntryParserFa
return new CompositeFileEntryParser(new FTPFileEntryParser[]
{
new OS400FTPEntryParser(config),
- new UnixFTPEntryParser(config)
+ new UnixFTPEntryParser(config,
+ config != null &&
FTPClientConfig.SYST_UNIX_TRIM_LEADING.equals(config.getServerSystemKey()))
});
}
}
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java?rev=1652696&r1=1652695&r2=1652696&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParser.java
Sat Jan 17 23:13:51 2015
@@ -158,7 +158,7 @@ public class UnixFTPEntryParser extends
*/
public UnixFTPEntryParser(FTPClientConfig config)
{
- this(config, true); // retain original behaviour (for now)
+ this(config, false);
}
/**
Modified:
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java?rev=1652696&r1=1652695&r2=1652696&view=diff
==============================================================================
---
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java
(original)
+++
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java
Sat Jan 17 23:13:51 2015
@@ -166,10 +166,10 @@ public class UnixFTPEntryParserTest exte
assertEquals("zxbox ", f.getName());
}
- public void testLeadingSpacesOriginal() { // this is the original
(non-ideal) behaviour
+ public void testLeadingSpacesDefault() { // the default has been changed
to keep spaces
FTPFile f = getParser().parseFTPEntry("drwxr-xr-x 2 john smith
group 4096 Mar 2 15:13 zxbox");
assertNotNull(f);
- assertEquals("zxbox", f.getName() ); // leading spaces dropped
+ assertEquals(" zxbox", f.getName() ); // leading spaces retained
}
public void testLeadingSpacesNET566() { // check new behaviour
@@ -178,7 +178,7 @@ public class UnixFTPEntryParserTest exte
assertEquals(" zxbox", f.getName() ); // leading spaces retained
}
- public void testTrimLeadingSpacesNET566() { // check new behaviour
alternate setting
+ public void testTrimLeadingSpacesNET566() { // check can trim spaces as
before
FTPFile f = new UnixFTPEntryParser(null,
true).parseFTPEntry("drwxr-xr-x 2 john smith group 4096 Mar 2
15:13 zxbox");
assertNotNull(f);
assertEquals("zxbox", f.getName() ); // leading spaces trimmed