fix: Do not fail if a file couldn't be copied

pull/26/head
Raphaël Vinot 2020-01-16 11:36:44 +01:00
parent f3cbeb87e4
commit 55b56c2422
2 changed files with 13 additions and 8 deletions

View File

@ -754,13 +754,14 @@ class KittenGroomerFileCheck(KittenGroomerBase):
self.process_archive(file) self.process_archive(file)
else: else:
if file.should_copy: if file.should_copy:
file.safe_copy() if file.safe_copy():
file.set_property('copied', True) file.set_property('copied', True)
print(file) if not file._validate_random_hashes():
if not file._validate_random_hashes(): # Something's fucked up.
# Something's fucked up. file.make_dangerous('The copied file is different from the one checked, removing.')
file.make_dangerous('The copied file is different from the one checked, removing.') file.dst_path.unlink()
file.dst_path.unlink() else:
file.set_property('copied', False)
self.write_file_to_log(file) self.write_file_to_log(file)
# TODO: Can probably handle cleaning up the tempdir better # TODO: Can probably handle cleaning up the tempdir better
if hasattr(file, 'tempdir_path'): if hasattr(file, 'tempdir_path'):

View File

@ -13,6 +13,7 @@ import hashlib
import shutil import shutil
import argparse import argparse
import stat import stat
import traceback
from pathlib import Path from pathlib import Path
from typing import Union, Optional, List, Dict, Any, Tuple, Iterator from typing import Union, Optional, List, Dict, Any, Tuple, Iterator
@ -188,14 +189,17 @@ class FileBase(object):
dst = self.dst_path dst = self.dst_path
try: try:
self.dst_dir.mkdir(exist_ok=True, parents=True) self.dst_dir.mkdir(exist_ok=True, parents=True)
shutil.copy(str(src), str(dst)) shutil.copy(src, dst)
current_perms = self._get_file_permissions(dst) current_perms = self._get_file_permissions(dst)
only_exec_bits = 0o0111 only_exec_bits = 0o0111
perms_no_exec = current_perms & (~only_exec_bits) perms_no_exec = current_perms & (~only_exec_bits)
dst.chmod(perms_no_exec) dst.chmod(perms_no_exec)
return True
except IOError as e: except IOError as e:
# Probably means we can't write in the dest dir # Probably means we can't write in the dest dir
self.add_error(e, '') self.add_error(e, '')
traceback.print_exc()
return False
def force_ext(self, extension: str): def force_ext(self, extension: str):
"""If dst_path does not end in `extension`, append .ext to it.""" """If dst_path does not end in `extension`, append .ext to it."""