cleanup the temp dir used for zip file validation
@@ -3278,14 +3278,17 @@ class ResourceFile(ResourceFileIRODSMixin):
@classmethod
def is_zip_file_valid(cls, res_zipfile):
- """Validates file/folder name of all files/folders contained in the specified zip file to check if any of them
- contains any of the banned characters.
- :param res_zipfile: a resource file that's a zip file
+ """Validates file/folder name of all files/folders contained in the specified zip file to check if any of the
+ files/folders contains any of the banned characters.
+ :param res_zipfile: a resource file an instance of ResourceFile that's a zip file
+ :returns: True or False
"""
from .hydroshare import get_file_from_irods
+
zip_temp_file_path = get_file_from_irods(resource=res_zipfile.resource, file_path=res_zipfile.storage_path)
temp_dir = os.path.dirname(zip_temp_file_path)
+ try:
if not zipfile.is_zipfile(zip_temp_file_path):
return False
@@ -3304,9 +3307,10 @@ class ResourceFile(ResourceFileIRODSMixin):
break
if not is_valid:
break
-
+ finally:
if os.path.isdir(temp_dir):
shutil.rmtree(temp_dir)
+
return is_valid
@classmethod
