mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2024-11-14 04:07:18 +00:00
Gracefully skip missing files in checksum list
This commit is contained in:
parent
e250df05de
commit
223896af29
|
@ -115,12 +115,7 @@ def _get_checksum(file):
|
||||||
proc = subprocess.run(['sha256sum', file], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
proc = subprocess.run(['sha256sum', file], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
proc_stdout = proc.stdout.decode('utf-8')
|
proc_stdout = proc.stdout.decode('utf-8')
|
||||||
if "No such file or directory" in proc_stdout:
|
if "No such file or directory" in proc_stdout:
|
||||||
print(
|
raise FileNotFoundError(f"'{file}' not found, can't produce sha256 checksum")
|
||||||
f'{colorama.Fore.RED}FileNotFound: {colorama.Fore.RESET}'
|
|
||||||
f"'{colorama.Fore.BLUE}{file}{colorama.Fore.RESET}' not found, can't produce "
|
|
||||||
"sha256 checksum, check the checksum file and remove this entry"
|
|
||||||
)
|
|
||||||
exit(2)
|
|
||||||
elif "Permission denied" in proc_stdout:
|
elif "Permission denied" in proc_stdout:
|
||||||
raise PermissionError(f"PermissionError: Unable to read file '{file}'")
|
raise PermissionError(f"PermissionError: Unable to read file '{file}'")
|
||||||
return proc_stdout.replace(f' {file}\n', '')
|
return proc_stdout.replace(f' {file}\n', '')
|
||||||
|
@ -132,7 +127,10 @@ def _command_exists(command):
|
||||||
|
|
||||||
|
|
||||||
def ask_update(file_path, checksum_file):
|
def ask_update(file_path, checksum_file):
|
||||||
new_checksum = _get_checksum(file_path)
|
try:
|
||||||
|
new_checksum = _get_checksum(file_path)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
file_line = f"'{colorama.Fore.BLUE}{file_path}{colorama.Fore.RESET}'"
|
file_line = f"'{colorama.Fore.BLUE}{file_path}{colorama.Fore.RESET}'"
|
||||||
if AUTO_UPDATE or _yes_no(' - ' + file_line + ' update checksum?'):
|
if AUTO_UPDATE or _yes_no(' - ' + file_line + ' update checksum?'):
|
||||||
|
@ -148,6 +146,7 @@ def ask_update(file_path, checksum_file):
|
||||||
|
|
||||||
def run_check():
|
def run_check():
|
||||||
checksums = _get_checksum_dict(CHECKSUM_FILE)
|
checksums = _get_checksum_dict(CHECKSUM_FILE)
|
||||||
|
|
||||||
not_matched = []
|
not_matched = []
|
||||||
for file, checksum in checksums.items():
|
for file, checksum in checksums.items():
|
||||||
try:
|
try:
|
||||||
|
@ -157,6 +156,11 @@ def run_check():
|
||||||
f"Checksum of '{colorama.Fore.BLUE}{file}{colorama.Fore.RESET}': "
|
f"Checksum of '{colorama.Fore.BLUE}{file}{colorama.Fore.RESET}': "
|
||||||
f'{colorama.Fore.YELLOW}SKIPPED [PermissionError - no read perms]')
|
f'{colorama.Fore.YELLOW}SKIPPED [PermissionError - no read perms]')
|
||||||
continue
|
continue
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(
|
||||||
|
f"Checksum of '{colorama.Fore.BLUE}{file}{colorama.Fore.RESET}': "
|
||||||
|
f'{colorama.Fore.YELLOW}SKIPPED [FileNotFound - fix checksum file]')
|
||||||
|
continue
|
||||||
|
|
||||||
if sha256_sum != checksum:
|
if sha256_sum != checksum:
|
||||||
not_matched.append(file)
|
not_matched.append(file)
|
||||||
|
|
Loading…
Reference in a new issue