mirror of
https://github.com/derrod/legendary.git
synced 2025-01-03 04:45:28 +00:00
[utils] Allow silent deletion of files
This commit is contained in:
parent
51c8b67f91
commit
40f8c553ba
|
@ -27,7 +27,8 @@ def delete_folder(path: str, recursive=True) -> bool:
|
|||
|
||||
|
||||
def delete_filelist(path: str, filenames: List[str],
|
||||
delete_root_directory: bool = False) -> bool:
|
||||
delete_root_directory: bool = False,
|
||||
silent: bool = False) -> bool:
|
||||
dirs = set()
|
||||
no_error = True
|
||||
|
||||
|
@ -40,6 +41,7 @@ def delete_filelist(path: str, filenames: List[str],
|
|||
try:
|
||||
os.remove(os.path.join(path, _dir, _fn))
|
||||
except Exception as e:
|
||||
if not silent:
|
||||
logger.error(f'Failed deleting file {filename} with {e!r}')
|
||||
no_error = False
|
||||
|
||||
|
@ -58,6 +60,7 @@ def delete_filelist(path: str, filenames: List[str],
|
|||
# directory has already been deleted, ignore that
|
||||
continue
|
||||
except Exception as e:
|
||||
if not silent:
|
||||
logger.error(f'Failed removing directory "{_dir}" with {e!r}')
|
||||
no_error = False
|
||||
|
||||
|
@ -65,6 +68,7 @@ def delete_filelist(path: str, filenames: List[str],
|
|||
try:
|
||||
os.rmdir(path)
|
||||
except Exception as e:
|
||||
if not silent:
|
||||
logger.error(f'Removing game directory failed with {e!r}')
|
||||
|
||||
return no_error
|
||||
|
|
Loading…
Reference in a new issue