You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/09/06 22:49:35 UTC

[commons-vfs] branch master updated: [VFS-769] fix .tgz and .tbz createFileSystem fails and add test (#94)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git


The following commit(s) were added to refs/heads/master by this push:
     new 4603740  [VFS-769] fix .tgz and .tbz createFileSystem fails and add test (#94)
4603740 is described below

commit 46037404b6460490b756fe156b7df5d42ae7bed8
Author: Lee <55...@users.noreply.github.com>
AuthorDate: Mon Sep 7 06:49:30 2020 +0800

    [VFS-769] fix .tgz and .tbz createFileSystem fails and add test (#94)
---
 .../org/apache/commons/vfs2/impl/providers.xml     |  4 --
 .../tar/test/CreateFileSystemTestCase.java         | 73 ++++++++++++++++++++++
 2 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/commons-vfs2/src/main/resources/org/apache/commons/vfs2/impl/providers.xml b/commons-vfs2/src/main/resources/org/apache/commons/vfs2/impl/providers.xml
index 332f2ff..86c1e81 100644
--- a/commons-vfs2/src/main/resources/org/apache/commons/vfs2/impl/providers.xml
+++ b/commons-vfs2/src/main/resources/org/apache/commons/vfs2/impl/providers.xml
@@ -158,12 +158,8 @@
     <extension-map extension="jar" scheme="jar"/>
     <extension-map extension="bz2" scheme="bz2"/>
     <extension-map extension="gz" scheme="gz"/>
-    <!--
     <extension-map extension="tgz" scheme="tgz"/>
     <extension-map extension="tbz2" scheme="tbz2"/>
-    -->
-    <extension-map extension="tgz" scheme="tar"/>
-    <extension-map extension="tbz2" scheme="tar"/>
 
     <!--
     <filter-map class-name="org.apache.commons.vfs2.content.bzip2.Bzip2Compress">
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/CreateFileSystemTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/CreateFileSystemTestCase.java
new file mode 100644
index 0000000..19ebfee
--- /dev/null
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/test/CreateFileSystemTestCase.java
@@ -0,0 +1,73 @@
+/*
+ * 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.tar.test;
+
+import org.apache.commons.vfs2.FileObject;
+import org.apache.commons.vfs2.FileSystemManager;
+import org.apache.commons.vfs2.VFS;
+import org.apache.commons.vfs2.provider.tar.TarFileObject;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * test use DefaultFileSystemManager.createFileSystem method to create tar,tgz,tbz2 file system
+ *
+ * @since 2.7.0
+ **/
+public class CreateFileSystemTestCase {
+
+    private FileObject createFileSystem(final String testFilePath) throws IOException {
+
+        final File testFile = new File(testFilePath);
+        FileSystemManager manager = VFS.getManager();
+
+        // create fileSystem and return fileObject
+        try (FileObject localFileObject = manager.resolveFile(testFile.getAbsolutePath())) {
+            return manager.createFileSystem(localFileObject);
+        }
+    }
+
+    @Test
+    public void testTarFile() throws IOException {
+
+        String testFilePath = "src/test/resources/test-data/test.tar";
+        try (FileObject fileObject = createFileSystem(testFilePath)) {
+            Assert.assertTrue(fileObject instanceof TarFileObject);
+        }
+    }
+
+    @Test
+    public void testTgzFile() throws IOException {
+
+        String testFilePath = "src/test/resources/test-data/test.tgz";
+        try (FileObject fileObject = createFileSystem(testFilePath)) {
+            Assert.assertTrue(fileObject instanceof TarFileObject);
+        }
+    }
+
+    @Test
+    public void testTbz2File() throws IOException {
+
+        String testFilePath = "src/test/resources/test-data/test.tbz2";
+        try (FileObject fileObject = createFileSystem(testFilePath)) {
+            Assert.assertTrue(fileObject instanceof TarFileObject);
+        }
+    }
+}