From b462ca98c51a48b455e89ae1c2c6b9126ce331c5 Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Fri, 25 Apr 2014 02:13:28 -0400 Subject: [PATCH] avoid to compress/decompress a non-file object Change-Id: I0c43f449175325ba9314e56151a822b3aee0ec21 Signed-off-by: Gui Chen --- mic/archive.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mic/archive.py b/mic/archive.py index 4f0e915..f25175b 100644 --- a/mic/archive.py +++ b/mic/archive.py @@ -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: -- 2.7.4