avoid to compress/decompress a non-file object
authorGui Chen <gui.chen@intel.com>
Fri, 25 Apr 2014 06:13:28 +0000 (02:13 -0400)
committeradmin <yuhuan.yang@samsung.com>
Thu, 4 Feb 2016 09:43:01 +0000 (17:43 +0800)
Change-Id: I0c43f449175325ba9314e56151a822b3aee0ec21
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/archive.py

index 4f0e915..f25175b 100644 (file)
@@ -175,6 +175,9 @@ def compress(file_path, compress_format):
     @compress_format: the compression format
     @retval: the path of the compressed file
     """
+    if not os.path.isfile(file_path):
+        raise OSError, "can't compress a file not existed: '%s'" % file_path
+
     try:
         func = _COMPRESS_FORMATS[compress_format]
     except KeyError:
@@ -188,6 +191,9 @@ def decompress(file_path, decompress_format=None):
     @decompress_format: the format for decompression, None for auto detection
     @retval: the path of the decompressed file
     """
+    if not os.path.isfile(file_path):
+        raise OSError, "can't decompress a file not existed: '%s'" % file_path
+
     try:
         func = _COMPRESS_FORMATS[decompress_format]
     except KeyError: