Tim Chase added the comment:
As requested by Ben Finney[1], adding my use-case here. I'm attempting to make
a hard-link from "a" to "b", but if "b" exists, os.link() will fail with an
EEXISTS. I don't want to do
os.unlink("b")
# power-outage here means "b" is gone
os.link("a", "b")
I can do something like
temp_name = tempfile.mktemp(dir=".")
os.link("a", temp_name)
try:
os.rename(temp_name, "b") # docs guarantee this is atomic
except OSError:
os.unlink(temp_name)
but mktemp() is marked as deprecated.
I'm okay with the stray temp-file floating around to clean up in the event of
power-loss after the os.link() but before the os.unlink() call, as is new info,
not disposing of existing file-names
[1] https://mail.python.org/pipermail/python-list/2017-April/721641.html
----------
nosy: +gumnos
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue26362>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com