maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1127703 - in /maven/wagon/trunk/wagon-providers/wagon-ftp/src: main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java
Date Wed, 25 May 2011 22:01:15 GMT
Author: struberg
Date: Wed May 25 22:01:15 2011
New Revision: 1127703

URL: http://svn.apache.org/viewvc?rev=1127703&view=rev
Log:
OWB-329 create nested directories recursively

We need to do that becaus only a few FTP servers support
direct deep MKD commands.
RFC-959 just specifies a single directory (not nested)

Modified:
    maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java
    maven/wagon/trunk/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java

Modified: maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java?rev=1127703&r1=1127702&r2=1127703&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ftp/src/main/java/org/apache/maven/wagon/providers/ftp/FtpWagon.java
Wed May 25 22:01:15 2011
@@ -49,6 +49,7 @@ import org.apache.maven.wagon.repository
 import org.apache.maven.wagon.resource.Resource;
 import org.codehaus.plexus.util.IOUtil;
 
+
 /**
  * FtpWagon 
  *
@@ -529,7 +530,7 @@ public class FtpWagon
                     if ( !ftp.changeWorkingDirectory( fileName ) )
                     {
                         // first, try to create it
-                        if ( ftp.makeDirectory( fileName ) )
+                        if ( makeFtpDirectoryRecursive( fileName ) )
                         {
                             if ( permissions != null )
                             {
@@ -671,4 +672,61 @@ public class FtpWagon
 
         fireTransferDebug( "completed = " + sourceFile.getAbsolutePath() );
     }
+
+    /**
+     * Recursively create directories.
+     * @param fileName the path to create (might be nested)
+     * @return ok
+     * @throws IOException
+     */
+    private boolean makeFtpDirectoryRecursive( String fileName ) throws IOException
+    {
+        if ( fileName == null || fileName.length() == 0 )
+        {
+            return false;
+        }
+
+        int slashPos = fileName.indexOf( "/" );
+        String oldPwd = null;
+        boolean ok = false;
+
+        if ( slashPos == 0 )
+        {
+            // this is an absolute directory
+            oldPwd = ftp.printWorkingDirectory();
+
+            // start with the root
+            ftp.changeWorkingDirectory( "/" );
+            fileName = fileName.substring( 1 );
+        }
+
+        if (  slashPos > 0 && slashPos < fileName.length() - 1 )
+        {
+            if ( oldPwd == null)
+            {
+                oldPwd = ftp.printWorkingDirectory();
+            }
+
+            String nextDir = fileName.substring( 0, slashPos );
+            ok |= ftp.makeDirectory( nextDir );
+
+            ftp.changeWorkingDirectory( nextDir );
+
+            // now create the deeper directories
+            String remainingDirs = fileName.substring( slashPos + 1 );
+            ok |= makeFtpDirectoryRecursive( remainingDirs );
+        }
+        else
+        {
+            ok = ftp.makeDirectory( fileName );
+        }
+
+        if ( oldPwd != null )
+        {
+            // change back to the old working directory
+            ftp.changeWorkingDirectory( oldPwd );
+        }
+
+        return ok;
+    }
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java?rev=1127703&r1=1127702&r2=1127703&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ftp/src/test/java/org/apache/maven/wagon/providers/ftp/FtpWagonTest.java
Wed May 25 22:01:15 2011
@@ -48,15 +48,6 @@ public class FtpWagonTest
     static private FtpServer server;
 
 
-    /**
-     * TODO: fix WAGON-329
-     * @throws Exception
-     */
-    @Override
-    public void testWagonPutDirectoryDeepDestination() throws Exception
-    {
-      //X TODO temporarily disabled
-    }
 
     /**
      * TODO: fix WAGON-329



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org


Mime
View raw message