Browse Source

HUE-3106 [filebrowser] Add support for full paths in zip file uploads

Directory sturucture in the archive is maintained inside the folder where zip file was uploaded.
krish 9 năm trước cách đây
mục cha
commit
7c86a75

+ 6 - 0
apps/filebrowser/src/filebrowser/lib/archives.py

@@ -97,6 +97,12 @@ class ZipArchive(Archive):
         dirs.append(name)
       else:
         files.append(name)
+        # self.zfh.namelist() sometimes doesn't return all the directories
+        # Go up the path one directory at the time
+        parent = os.path.dirname(name)
+        while parent != '' and parent not in dirs:
+          dirs.append(parent)
+          parent = os.path.dirname(parent)
     return (dirs, files)
 
   def _create_files(self, basepath, files=[]):

+ 10 - 0
apps/filebrowser/src/filebrowser/lib/archives_test.py

@@ -35,6 +35,16 @@ class ArchiveTest(unittest.TestCase):
     assert_true(os.path.isfile(directory + '/test.txt'))
     assert_equal(os.path.getsize(directory + '/test.txt'), 4)
 
+    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test5.zip')
+
+    # Extract the file
+    # This file should only have 'test.txt' in it
+    directory = archives.archive_factory(FILE, 'zip').extract()
+    assert_true(os.path.exists(directory))
+    assert_true(os.path.isdir(directory))
+    assert_true(os.path.isfile(directory + '/tmp/temp/test.txt'))
+    assert_equal(os.path.getsize(directory + '/tmp/temp/test.txt'), 5)
+
   def test_tgz(self):
     FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test.tar.gz')
 

BIN
apps/filebrowser/src/filebrowser/test_data/test5.zip