Message292648
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 |
|
Date |
User |
Action |
Args |
2017-05-01 02:48:06 | gumnos | set | recipients:
+ gumnos, georg.brandl, ethan.furman, bignose, serhiy.storchaka |
2017-05-01 02:48:05 | gumnos | set | messageid: <1493606885.95.0.919205719406.issue26362@psf.upfronthosting.co.za> |
2017-05-01 02:48:05 | gumnos | link | issue26362 messages |
2017-05-01 02:48:05 | gumnos | create | |
|