file created to reserve name:
fd = os.open(candidate, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
Later:
with open(out_path, "wb") as f:
f.write(...)
Problems:
empty file created first
Then overwritten
program crash between steps = leftover empty file still exists
Also unnecessary disk write
Better approach:
Compute unique name without creating files, OR open with O_EXCL + write immediately
file created to reserve name:
fd = os.open(candidate, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
Later:
with open(out_path, "wb") as f:
f.write(...)
Problems:
empty file created first
Then overwritten
program crash between steps = leftover empty file still exists
Also unnecessary disk write
Better approach:
Compute unique name without creating files, OR open with O_EXCL + write immediately