Add non-empty directory zip entries in the csar 94/98694/1
authorLianhao Lu <lianhao.lu@intel.com>
Thu, 21 Nov 2019 03:11:20 +0000 (11:11 +0800)
committerLianhao Lu <lianhao.lu@intel.com>
Thu, 21 Nov 2019 03:11:52 +0000 (11:11 +0800)
Issue-ID: VNFSDK-517

Change-Id: Ib699949ae72a3d3a7d141ad5ddc331343dac16ac
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
vnfsdk_pkgtools/packager/csar.py

index af84974..1bf5c20 100644 (file)
@@ -142,6 +142,13 @@ def write(source, entry, destination, args):
     LOG.debug('Compressing root directory to ZIP')
     with zipfile.ZipFile(destination, 'w', zipfile.ZIP_DEFLATED) as f:
         for root, dirs, files in os.walk(source):
+            # add dir entries
+            for dir in dirs:
+                dir_full_path = os.path.join(root, dir)
+                dir_relative_path = os.path.relpath(dir_full_path, source) + os.sep
+                LOG.debug('Writing to archive: {0}'.format(dir_relative_path))
+                f.write(dir_full_path + os.sep, dir_relative_path)
+
             for file in files:
                 file_full_path = os.path.join(root, file)
                 # skip manifest file here in case we need to generate digest
@@ -152,13 +159,6 @@ def write(source, entry, destination, args):
                     if manifest_file and args.digest:
                         LOG.debug('Update file digest: {0}'.format(file_relative_path))
                         manifest_file.add_file(file_relative_path, args.digest)
-            # add empty dir
-            for dir in dirs:
-                dir_full_path = os.path.join(root, dir)
-                if len(os.listdir(dir_full_path)) == 0:
-                    dir_relative_path = os.path.relpath(dir_full_path, source) + os.sep
-                    LOG.debug('Writing to archive: {0}'.format(dir_relative_path))
-                    f.write(dir_full_path + os.sep, dir_relative_path)
 
         if manifest_file:
             LOG.debug('Update manifest file to temporary file')