cptemplate,error.py: Add handling for when target file already exists
This commit is contained in:
parent
48ca334377
commit
b2925bfd23
@ -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())
|
||||
|
@ -12,6 +12,7 @@ E_NOFILESELECTED = 2
|
||||
E_NOEDITORFOUND = 3
|
||||
E_NO_RESULTS = 4
|
||||
E_USER_RESPONSE_NO = 5
|
||||
E_FILE_EXISTS = 6
|
||||
|
||||
# ----- Messages -----
|
||||
NO_FILE_SELECTED_MESSAGE = "No file was selected."
|
||||
|
Loading…
x
Reference in New Issue
Block a user