cptemplate,error.py: Add handling for when target file already exists

This commit is contained in:
Eric Torres
2020-10-24 17:49:19 -07:00
parent 48ca334377
commit b2925bfd23
2 changed files with 8 additions and 4 deletions

View File

@ -78,9 +78,12 @@ if __name__ == "__main__":
try:
dest_file.touch(mode=0o600, exist_ok=False)
except FileExistsError:
# force_overwrite true: overwrite
# force_overwrite false: print error message
raise NotImplementedError("Implement if file already exists")
except FileExistsError as e:
if args.force_overwrite:
dest_file.touch(mode=0o600, exist_ok=True)
dest_file.write_bytes(selected_file.read_bytes())
else:
print(e)
exit(error.E_FILE_EXISTS)
else:
dest_file.write_bytes(selected_file.read_bytes())