Author: ecki Date: Mon Sep 28 18:25:02 2015 New Revision: 1705741 URL: http://svn.apache.org/viewvc?rev=1705741&view=rev Log: [VFS-583] Avoid layered filesystem leak when options are used. Added tests.
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractLayeredFileProvider.java commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTarTestCase.java commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/UrlTests.java Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractLayeredFileProvider.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractLayeredFileProvider.java?rev=1705741&r1=1705740&r2=1705741&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractLayeredFileProvider.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/provider/AbstractLayeredFileProvider.java Mon Sep 28 18:25:02 2015 @@ -80,7 +80,7 @@ public abstract class AbstractLayeredFil { // Check if cached final FileName rootName = file.getName(); - FileSystem fs = findFileSystem(rootName, null); + FileSystem fs = findFileSystem(rootName, fileSystemOptions); // TODO if (fs == null) { // Create the file system Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTarTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTarTestCase.java?rev=1705741&r1=1705740&r2=1705741&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTarTestCase.java (original) +++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/provider/tar/test/NestedTarTestCase.java Mon Sep 28 18:25:02 2015 @@ -20,7 +20,11 @@ import junit.framework.Test; import org.apache.commons.AbstractVfsTestCase; import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemConfigBuilder; import org.apache.commons.vfs2.FileSystemManager; +import org.apache.commons.vfs2.FileSystemOptions; +import org.apache.commons.vfs2.auth.StaticUserAuthenticator; +import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; import org.apache.commons.vfs2.provider.tar.TarFileProvider; import org.apache.commons.vfs2.test.AbstractProviderTestConfig; @@ -60,12 +64,16 @@ public class NestedTarTestCase @Override public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception { + // We test with non-empty FS options to make sure they are propagated + final FileSystemOptions opts = new FileSystemOptions(); + DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, new StaticUserAuthenticator("domain", null, null)); + // Locate the base Tar file final String tarFilePath = AbstractVfsTestCase.getTestResource("nested.tar").getAbsolutePath(); - final String uri = "tar:file:" + tarFilePath + "!/test.tar"; - final FileObject tarFile = manager.resolveFile(uri); // Now build the nested file system + final String uri = "tar:file:" + tarFilePath + "!/test.tar"; + final FileObject tarFile = manager.resolveFile(uri, opts); final FileObject nestedFS = manager.createFileSystem(tarFile); return nestedFS.resolveFile("/"); } Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/UrlTests.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/UrlTests.java?rev=1705741&r1=1705740&r2=1705741&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/UrlTests.java (original) +++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/UrlTests.java Mon Sep 28 18:25:02 2015 @@ -23,6 +23,7 @@ import java.net.URLConnection; import org.apache.commons.vfs2.Capability; import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemOptions; /** * URL test cases for providers. @@ -88,6 +89,25 @@ public class UrlTests } /** + * Tests content. + */ + public void testURLContentProvider() throws Exception + { + // Test non-empty file + FileObject file = getReadFolder().resolveFile("file1.txt"); + assertTrue(file.exists()); + + String uri = file.getURL().toExternalForm(); + FileSystemOptions options = getReadFolder().getFileSystem().getFileSystemOptions(); + + FileObject f1 = getManager().resolveFile(uri, options); + FileObject f2 = getManager().resolveFile(uri, options); + + assertEquals("Two files resolved by URI must be equals on " + uri, f1, f2); + assertSame("Resolving two times should not produce new filesystem on " + uri, f1.getFileSystem(), f2.getFileSystem()); + } + + /** * Tests that unknown files have no content. */ public void testUnknownURL() throws Exception