Browse Source

Fix _expand_archive()

In cases where System.IO.Compression.ZipFile is available on the
windows minion, if the destination folder exists, it will cause
an error.

Where this component is not available, if the target folder exists
and there are conflicting files inside it with what's inside the
archive, it will error out.

In both cases, ensuring that the destination folder does not exist
will fix the issue.

If the destination folder is the root folder or is within the
%WINDOWS% folder, we do not remove it.
Gabriel Adrian Samfira 6 năm trước cách đây
mục cha
commit
9195fb0744
1 tập tin đã thay đổi với 14 bổ sung1 xóa
  1. 14 1
      coriolis/osmorphing/windows.py

+ 14 - 1
coriolis/osmorphing/windows.py

@@ -9,6 +9,7 @@ import uuid
 from oslo_log import log as logging
 
 from coriolis import exception
+from coriolis import utils
 from coriolis.osmorphing import base
 
 LOG = logging.getLogger(__name__)
@@ -146,9 +147,21 @@ class BaseWindowsMorphingTools(base.BaseOSMorphingTools):
         self._conn.exec_ps_command("Dismount-DiskImage '%s'" % path,
                                    ignore_stdout=True)
 
-    def _expand_archive(self, path, destination):
+    @utils.retry_on_error()
+    def _expand_archive(self, path, destination, overwrite=True):
         LOG.info("Expanding archive \"%(path)s\" in \"%(destination)s\"",
                  {"path": path, "destination": destination})
+
+        if self._conn.test_path(destination):
+            LOG.info("Destination folder %s already exists" % destination)
+            if overwrite:
+                if destination.endswith(":\\") or ":\\Windows" in destination:
+                    LOG.warn(
+                        "Not removing target directory, as it is either the "
+                        "root directory or is within the Windows directory")
+                else:
+                    self._conn.exec_ps_command(
+                        "rm -recurse -force %s" % destination)
         self._conn.exec_ps_command(
             "if(([System.Management.Automation.PSTypeName]"
             "'System.IO.Compression.ZipFile').Type -or "