mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r723482 - in /mina/ftpserver/trunk: core/src/main/java/org/apache/ftpserver/command/impl/ core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/ core/src/main/java/org/apache/ftpserver/util/ core/src/main/resources/org/apache/ftp...
Date Thu, 04 Dec 2008 23:05:54 GMT
Author: dlat
Date: Thu Dec  4 15:05:54 2008
New Revision: 723482

URL: http://svn.apache.org/viewvc?rev=723482&view=rev
Log:
FTPSERVER-231 MFMT Commad does not work on file/path names that have one or more white spaces
FTPSERVER-232 MFMT command always returns a 2XX reply even if the date could not be set
FTPSERVER-234 TYPE command with no argument

Modified:
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/MFMT.java
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/TYPE.java
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/DateUtils.java
    mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
    mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/MFMTTest.java
    mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/LISTFileFormaterTest.java
    mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/MLSTFileFormaterTest.java
    mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/NLSTFileFormaterTest.java
    mina/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FtpFile.java

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/MFMT.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/MFMT.java?rev=723482&r1=723481&r2=723482&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/MFMT.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/MFMT.java Thu
Dec  4 15:05:54 2008
@@ -20,11 +20,8 @@
 package org.apache.ftpserver.command.impl;
 
 import java.io.IOException;
-import java.text.DateFormat;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.TimeZone;
 
 import org.apache.ftpserver.command.AbstractCommand;
 import org.apache.ftpserver.ftplet.FtpFile;
@@ -33,6 +30,7 @@
 import org.apache.ftpserver.impl.FtpIoSession;
 import org.apache.ftpserver.impl.FtpServerContext;
 import org.apache.ftpserver.impl.LocalizedFtpReply;
+import org.apache.ftpserver.util.DateUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -56,7 +54,6 @@
             final FtpServerContext context, final FtpRequest request)
             throws IOException {
 
-        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
         
         // reset state variables
         session.resetState();
@@ -75,7 +72,7 @@
             return;
         }
         
-        String[] arguments = argument.split(" ");
+        String[] arguments = argument.split(" ",2);
 
         if(arguments.length != 2) {
             session
@@ -90,12 +87,10 @@
         }
        
         String timestamp = arguments[0].trim();
-        
-        df.setLenient(false);
-        df.setTimeZone(TimeZone.getTimeZone("GMT"));
-        
+       
         try {
-            Date time = df.parse(timestamp);
+            
+            Date time = DateUtils.parseFTPDate(timestamp);
             
             String fileName = arguments[1].trim();
             
@@ -133,9 +128,17 @@
                 return;
             }
 
+             // check if we can set date and retrieve the actual date stored for the file.
+             if (file.setLastModified(time.getTime())) {
+             //    timestamp=DateUtils.getFtpDate(time.getTime());
+             }
+             // we couldn't set the date.
+             else{
+                 session.write(LocalizedFtpReply.translate(session, request, context,
+                         FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "MFMT",
+                         fileName));
+             }
             // all checks okay, lets go
-            file.setLastModified(time.getTime());
-
             session
             .write(LocalizedFtpReply
                     .translate(
@@ -143,7 +146,7 @@
                             request,
                             context,
                             FtpReply.REPLY_213_FILE_STATUS,
-                            "MFMT", "ModifyTime=" + timestamp + " " + fileName));
+                            "MFMT", "Modify=" + timestamp + "; " + fileName));
             return;
 
         } catch (ParseException e) {

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/TYPE.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/TYPE.java?rev=723482&r1=723481&r2=723482&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/TYPE.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/TYPE.java Thu
Dec  4 15:05:54 2008
@@ -59,6 +59,17 @@
         char type = 'A';
         if (request.hasArgument()) {
             type = request.getArgument().charAt(0);
+        }else{
+            // no type specified
+            session
+            .write(LocalizedFtpReply
+                    .translate(
+                            session,
+                            request,
+                            context,
+                            FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
+                            "TYPE", null));
+            return;
         }
 
         // set type

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java?rev=723482&r1=723481&r2=723482&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
(original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
Thu Dec  4 15:05:54 2008
@@ -189,8 +189,8 @@
     /**
      * {@inheritDoc}
      */
-    public void setLastModified(long time) {
-        file.setLastModified(time);
+    public boolean setLastModified(long time) {
+        return file.setLastModified(time);
     }
     
     /**

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/DateUtils.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/DateUtils.java?rev=723482&r1=723481&r2=723482&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/DateUtils.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/DateUtils.java Thu Dec
 4 15:05:54 2008
@@ -19,8 +19,13 @@
 
 package org.apache.ftpserver.util;
 
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.GregorianCalendar;
+import java.util.TimeZone;
 
 /**
  * <strong>Internal class, do not use directly.</strong>
@@ -35,6 +40,18 @@
     private final static String[] MONTHS = { "Jan", "Feb", "Mar", "Apr", "May",
             "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
 
+    
+    /*
+     * Creates the DateFormat object used to parse/format
+     * dates in FTP format.
+     */
+    private  final static DateFormat createFTPDateFormat(){
+        DateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
+        df.setLenient(false);
+        df.setTimeZone(TimeZone.getTimeZone("GMT"));
+        return df;
+    }
+    
     /**
      * Get unix style date string.
      */
@@ -199,4 +216,15 @@
         sb.append(milli);
         return sb.toString();
     }
+    /*
+     *  Parses a date in the format used by the FTP commands 
+     *  involving dates(MFMT, MDTM)
+     */
+    public final static Date parseFTPDate(String dateStr) throws ParseException{
+       // TODO: Here we could use a single DateFormat (in a thread-safe way)  
+       //  instead of one per call 
+        return createFTPDateFormat().parse(dateStr);
+        
+    }
+    
 }

Modified: mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties?rev=723482&r1=723481&r2=723482&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
(original)
+++ mina/ftpserver/trunk/core/src/main/resources/org/apache/ftpserver/message/FtpStatus.properties
Thu Dec  4 15:05:54 2008
@@ -277,5 +277,6 @@
 
 
 213.MFMT={output.msg}
+450.MFMT=Could not perform action on file {output.msg}.
 501.MFMT.invalid=Command Not Implemented for the Specified Arguments
 550.MFMT.filemissing=File missing {output.msg}
\ No newline at end of file

Modified: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/MFMTTest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/MFMTTest.java?rev=723482&r1=723481&r2=723482&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/MFMTTest.java
(original)
+++ mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/MFMTTest.java
Thu Dec  4 15:05:54 2008
@@ -40,6 +40,8 @@
 
     private static final File TEST_FILE_IN_DIR1 = new File(TEST_DIR1,
             "test4.txt");
+    private static final File TEST_FILE_BLANK_SPACES=new File(ROOT_DIR,"my test.txt");
+    
 
     private static final Calendar EXPECTED_TIME = new GregorianCalendar(2002, 6, 17, 21,
7, 15);        
     static {
@@ -53,11 +55,11 @@
         assertTrue(TEST_FILE1.createNewFile());
         assertTrue(TEST_DIR1.mkdir());
         assertTrue(TEST_FILE_IN_DIR1.createNewFile());
-        
+        assertTrue(TEST_FILE_BLANK_SPACES.createNewFile());
         
         client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
     }
-
+   
     public void testNoArgument() throws Exception {
         // must return 500 or 501 errors
         assertEquals(501, client.sendCommand("MFMT"));
@@ -69,8 +71,8 @@
     }
 
     public void testNoManyArguments() throws Exception {
-        // must return 500 or 501 errors
-        assertEquals(501, client.sendCommand("MFMT", "20020717210715 test1.txt too many"));
+        // must return 550 errors as a filename can contain blank spaces
+        assertEquals(550, client.sendCommand("MFMT", "20020717210715 test1.txt too many"));
     }
     
     public void testNonTimestampArgument() throws Exception {
@@ -127,5 +129,11 @@
         
         assertEquals(EXPECTED_TIME.getTimeInMillis(), TEST_FILE_IN_DIR1.lastModified());
     }
+    @SuppressWarnings("deprecation")
+    public void testSetTimeFileWithSpaces() throws Exception{
+        assertEquals(213, client.sendCommand("MFMT", "20020717210715 my test.txt"));
+        
+        assertEquals(EXPECTED_TIME.getTimeInMillis(),TEST_FILE_BLANK_SPACES.lastModified());
+    }
     
 }

Modified: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/LISTFileFormaterTest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/LISTFileFormaterTest.java?rev=723482&r1=723481&r2=723482&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/LISTFileFormaterTest.java
(original)
+++ mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/LISTFileFormaterTest.java
Thu Dec  4 15:05:54 2008
@@ -130,9 +130,8 @@
             return false;
         }
 
-        public void setLastModified(long time) {
-            // TODO Auto-generated method stub
-            
+        public boolean setLastModified(long time) {
+            return false;
         }
     }
 

Modified: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/MLSTFileFormaterTest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/MLSTFileFormaterTest.java?rev=723482&r1=723481&r2=723482&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/MLSTFileFormaterTest.java
(original)
+++ mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/MLSTFileFormaterTest.java
Thu Dec  4 15:05:54 2008
@@ -126,8 +126,8 @@
             return false;
         }
 
-        public void setLastModified(long time) {
-            // TODO Auto-generated method stub
+        public boolean setLastModified(long time) {
+           return false;
             
         }
     }

Modified: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/NLSTFileFormaterTest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/NLSTFileFormaterTest.java?rev=723482&r1=723481&r2=723482&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/NLSTFileFormaterTest.java
(original)
+++ mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/commands/impl/listing/NLSTFileFormaterTest.java
Thu Dec  4 15:05:54 2008
@@ -122,8 +122,8 @@
             return false;
         }
 
-        public void setLastModified(long time) {
-            // TODO Auto-generated method stub
+        public boolean setLastModified(long time) {
+            return false;
             
         }
     }

Modified: mina/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FtpFile.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FtpFile.java?rev=723482&r1=723481&r2=723482&view=diff
==============================================================================
--- mina/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FtpFile.java
(original)
+++ mina/ftpserver/trunk/ftplet-api/src/main/java/org/apache/ftpserver/ftplet/FtpFile.java
Thu Dec  4 15:05:54 2008
@@ -116,7 +116,7 @@
      * Set the last modified time stamp of a file
      * @param time The last modified time, in milliseconds since the epoch. See {@link File#setLastModified(long)}.
      */
-    void setLastModified(long time);
+    boolean setLastModified(long time);
     
     /**
      * Get file size.



Mime
View raw message