tinypilot icon indicating copy to clipboard operation
tinypilot copied to clipboard

Make decision whether `atomic_file.create` should overwrite existing file

Open jotaen4tinypilot opened this issue 3 years ago • 2 comments

atomic_file.create uses shutil.move under the hood. If a file with the same name already exists at the target location, it seems like that is silently overwritten then.

This behaviour is neither documented nor tested right now, so I don’t think we have considered this case. It would help if the desired behaviour was defined, and then we should add tests and a comment (one way or the other).

I don’t have a strong preference, I think good points can be made either way.

In case we decide that overwriting is what we want, we should double check all calling code, to see whether we need to adjust or cleanup things there.

jotaen4tinypilot avatar Mar 03 '22 14:03 jotaen4tinypilot

Good catch! I think we should match the semantics of open(path, 'w'), so it should overwrite existing files.

mtlynch avatar Mar 03 '22 15:03 mtlynch

I think we should match the semantics of open(path, 'w'), so it should overwrite existing files.

I agree with this.

jdeanwallace avatar Mar 04 '22 05:03 jdeanwallace