commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1787594 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/provider/ftp/ core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/ src/changes/
Date Sun, 19 Mar 2017 08:51:28 GMT
Author: ggregory
Date: Sun Mar 19 08:51:27 2017
New Revision: 1787594

URL: http://svn.apache.org/viewvc?rev=1787594&view=rev
Log:
[VFS-620] FileObject.moveTo(FileObject) API doesn't work well for a Linux FTP.

Added:
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderUserDirTestCase.java
Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java?rev=1787594&r1=1787593&r2=1787594&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
(original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
Sun Mar 19 08:51:27 2017
@@ -509,8 +509,8 @@ public class FtpFileObject extends Abstr
             final FtpClient ftpClient = getAbstractFileSystem().getClient();
             try
             {
-                final String oldName = getName().getPath();
-                final String newName = newFile.getName().getPath();
+                final String oldName = relPath;
+                final String newName = ((FtpFileObject) FileObjectUtils.getAbstractFileObject(newFile)).getRelPath();
                 ok = ftpClient.rename(oldName, newName);
             }
             finally

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java?rev=1787594&r1=1787593&r2=1787594&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderTestCase.java
Sun Mar 19 08:51:27 2017
@@ -34,6 +34,7 @@ import org.apache.commons.vfs2.test.Prov
 import org.apache.commons.vfs2.util.FreeSocketPortUtil;
 import org.apache.ftpserver.FtpServer;
 import org.apache.ftpserver.FtpServerFactory;
+import org.apache.ftpserver.ftplet.FileSystemFactory;
 import org.apache.ftpserver.ftplet.FtpException;
 import org.apache.ftpserver.ftplet.UserManager;
 import org.apache.ftpserver.listener.ListenerFactory;
@@ -83,11 +84,12 @@ public class FtpProviderTestCase extends
 
     /**
      * Creates and starts an embedded Apache FTP Server (MINA).
-     *
+     * @param rootDirectory the local FTP server rootDirectory
+     * @param fileSystemFactory optional local FTP server FileSystemFactory
      * @throws FtpException
      * @throws IOException
      */
-    static void setUpClass() throws FtpException, IOException
+    static void setUpClass(String rootDirectory, FileSystemFactory fileSystemFactory) throws
FtpException, IOException
     {
         if (Server != null)
         {
@@ -103,8 +105,12 @@ public class FtpProviderTestCase extends
         final BaseUser user = (BaseUser) userManager.getUserByName("test");
         // Pickup the home dir value at runtime even though we have it set in the user prop
file
         // The user prop file requires the "homedirectory" to be set
-        user.setHomeDirectory(getTestDirectory());
+        user.setHomeDirectory(rootDirectory);
+        userManager.save(user);
         serverFactory.setUserManager(userManager);
+        if (fileSystemFactory != null) {
+            serverFactory.setFileSystem(fileSystemFactory);
+        }
         final ListenerFactory factory = new ListenerFactory();
         // set the port of the listener
         factory.setPort(SocketPort);
@@ -122,14 +128,22 @@ public class FtpProviderTestCase extends
      */
     public static Test suite() throws Exception
     {
-        return new ProviderTestSuite(new FtpProviderTestCase())
+        return suite(new FtpProviderTestCase());
+    }
+
+    /**
+     * Creates the test suite for subclasses of the ftp file system.
+     */
+    protected static Test suite(final FtpProviderTestCase testCase) throws Exception
+    {
+        return new ProviderTestSuite(testCase)
         {
             @Override
             protected void setUp() throws Exception
             {
                 if (getSystemTestUriOverride() == null)
                 {
-                    setUpClass();
+                    setUpClass(testCase.getFtpRootDir(), testCase.getFtpFileSystem());
                 }
                 super.setUp();
             }
@@ -176,6 +190,7 @@ public class FtpProviderTestCase extends
         }
         final FileSystemOptions opts = new FileSystemOptions();
         final FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance();
+        builder.setUserDirIsRoot(opts, getUserDirIsRoot());
         builder.setPassiveMode(opts, true);
         // FtpFileType.BINARY is the default
         builder.setFileType(opts, FtpFileType.BINARY);
@@ -185,6 +200,30 @@ public class FtpProviderTestCase extends
     }
 
     /**
+     * Gets the setting for UserDirIsRoot.
+     */
+    protected boolean getUserDirIsRoot()
+    {
+        return false;
+    }
+
+    /**
+     * Gets option file system factory for local FTP server.
+     */
+    protected FileSystemFactory getFtpFileSystem() throws IOException {
+        // use default
+        return null;
+    }
+
+    /**
+     * Gets the root of the local FTP Server file system.
+     */
+    protected String getFtpRootDir()
+    {
+        return getTestDirectory();
+    }
+
+    /**
      * Prepares the file system manager.
      */
     @Override

Added: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderUserDirTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderUserDirTestCase.java?rev=1787594&view=auto
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderUserDirTestCase.java
(added)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/FtpProviderUserDirTestCase.java
Sun Mar 19 08:51:27 2017
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.vfs2.provider.ftp.test;
+
+import junit.framework.Test;
+import org.apache.commons.io.FileUtils;
+import org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory;
+import org.apache.ftpserver.ftplet.FileSystemFactory;
+import org.apache.ftpserver.ftplet.FileSystemView;
+import org.apache.ftpserver.ftplet.FtpException;
+import org.apache.ftpserver.ftplet.User;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+
+/**
+ * Tests for FTP file systems (with homeDirIsRoot=true).
+ */
+public class FtpProviderUserDirTestCase extends FtpProviderTestCase
+{
+    /**
+     * Creates the test suite for the ftp file system.
+     */
+    public static Test suite() throws Exception
+    {
+        return suite(new FtpProviderUserDirTestCase());
+    }
+
+    /**
+     * Prepares the file system manager.
+     */
+    @Override
+    protected boolean getUserDirIsRoot()
+    {
+        return true;
+    }
+
+    /**
+     * Gets option file system factory for local FTP server.
+     */
+    @Override
+    protected FileSystemFactory getFtpFileSystem() throws IOException {
+        // simulate a non-root home directory by copying test directory to it
+        final File testDir =  new File(getTestDirectory());
+        final File rootDir = new File(testDir, "homeDirIsRoot");
+        final File homesDir = new File(rootDir, "home");
+        final File initialDir = new File(homesDir, "test");
+        FileUtils.deleteDirectory(rootDir);
+        //noinspection ResultOfMethodCallIgnored
+        rootDir.mkdir();
+        FileUtils.copyDirectory(testDir, initialDir, new FileFilter()
+        {
+            @Override
+            public boolean accept(File pathname)
+            {
+                return !pathname.getPath().contains(rootDir.getName());
+            }
+        });
+
+        return new NativeFileSystemFactory()
+        {
+            @Override
+            public FileSystemView createFileSystemView(User user) throws FtpException
+            {
+                FileSystemView fsView = super.createFileSystemView(user);
+                fsView.changeWorkingDirectory("home/test");
+                return fsView;
+            }
+        };
+    }
+
+    /**
+     * Gets the root of the local FTP Server file system.
+     */
+    @Override
+    protected String getFtpRootDir()
+    {
+        return new File(getTestDirectory(), "homeDirIsRoot").getPath();
+    }
+
+
+}

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java?rev=1787594&r1=1787593&r2=1787594&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/ftp/test/MultipleConnectionTestCase.java
Sun Mar 19 08:51:27 2017
@@ -35,7 +35,7 @@ public class MultipleConnectionTestCase
     @BeforeClass
     public static void setUpClass() throws FtpException, IOException
     {
-        FtpProviderTestCase.setUpClass();
+        FtpProviderTestCase.setUpClass(FtpProviderTestCase.getTestDirectory(), null);
     }
 
     @AfterClass

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1787594&r1=1787593&r2=1787594&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Sun Mar 19 08:51:27 2017
@@ -65,6 +65,9 @@ The <action> type attribute can be add,u
      <action issue="VFS-621" dev="ggregory" type="update">
         Add API VFS.setManager(FileSystemManager).
      </action>
+     <action issue="VFS-620" dev="ggregory" type="fix" due-to="stevezhuang">
+        FileObject.moveTo(FileObject) API doesn't work well for a Linux FTP.
+     </action>
    </release>  
     <release version="2.1" date="2016-05-19" description="New features and bug fix release.
 



Mime
View raw message