Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A86E9200C37 for ; Sun, 19 Mar 2017 09:51:31 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9B00B160B7D; Sun, 19 Mar 2017 08:51:31 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BDECD160B6E for ; Sun, 19 Mar 2017 09:51:30 +0100 (CET) Received: (qmail 48858 invoked by uid 500); 19 Mar 2017 08:51:29 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 48849 invoked by uid 99); 19 Mar 2017 08:51:29 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Mar 2017 08:51:29 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id A5F0D3A0915 for ; Sun, 19 Mar 2017 08:51:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170319085128.A5F0D3A0915@svn01-us-west.apache.org> archived-at: Sun, 19 Mar 2017 08:51:31 -0000 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 type attribute can be add,u Add API VFS.setManager(FileSystemManager). + + FileObject.moveTo(FileObject) API doesn't work well for a Linux FTP. +