Author gumnos
Recipients bignose, ethan.furman, georg.brandl, gumnos, serhiy.storchaka
Date 2017-05-01.02:48:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1493606885.95.0.919205719406.issue26362@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2017-05-01 02:48:06gumnossetrecipients: + gumnos, georg.brandl, ethan.furman, bignose, serhiy.storchaka
2017-05-01 02:48:05gumnossetmessageid: <1493606885.95.0.919205719406.issue26362@psf.upfronthosting.co.za>
2017-05-01 02:48:05gumnoslinkissue26362 messages
2017-05-01 02:48:05gumnoscreate