more check before extracting archive
authorHuanhuan Li <huanhuanx.li@intel.com>
Wed, 7 May 2014 05:38:00 +0000 (13:38 +0800)
committeradmin <yuhuan.yang@samsung.com>
Thu, 4 Feb 2016 09:46:39 +0000 (17:46 +0800)
Change-Id: Ieca43aa54cd384392b288aadd66c3e443eaca701

mic/archive.py

index 786ccf4..1268f94 100644 (file)
@@ -425,6 +425,16 @@ def extract_archive(archive_name, target_name):
     @target_name: the directory name where the target locates
     @retval: the extracting result
     """
+    if not os.path.exists(archive_name):
+        raise OSError, "archived object does not exist: '%s'" % archive_name
+
+    archive_name = os.path.abspath(archive_name)
+    target_name = os.path.abspath(target_name)
+
+    if os.path.exists(target_name) and not os.path.isdir(target_name):
+        raise OSError, "%s should be directory where extracted files locate"\
+                        % target_name
+
     if not os.path.exists(target_name):
         os.makedirs(target_name)