tempname.mktemp functionality deprecation

Dan Stromberg drsalists at gmail.com
Sun Apr 30 19:50:22 EDT 2017


On Sat, Apr 29, 2017 at 11:45 AM, Tim Chase
<python.list at tim.thechases.com> wrote:
> Working on some deduplication code, I want do my my best at
> performing an atomic re-hard-linking atop an existing file, akin to
> "ln -f source.txt dest.txt"
>
> However, when I issue
>
>   os.link("source.txt", "dest.txt")
>
> it fails with an OSError (EEXISTS).  This isn't surprising as it's
> documented.  Unfortunately, os.link doesn't support something like
>
>   os.link("source.txt", "dest.txt", force=True)

FWIW, ln -f appears to unlink on Linux Mint 18 (GNU coreutils 8.25):
$ strace -f ln -f file file2 2>&1 | tail -15
below cmd output started 2017 Sun Apr 30 04:47:53 PM PDT
munmap(0x7f804fcb4000, 147404)          = 0
brk(NULL)                               = 0x225c000
brk(0x227d000)                          = 0x227d000
stat("file2", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
lstat("file", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
lstat("file2", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
linkat(AT_FDCWD, "file", AT_FDCWD, "file2", 0) = -1 EEXIST (File exists)
unlink("file2")                         = 0
linkat(AT_FDCWD, "file", AT_FDCWD, "file2", 0) = 0
lseek(0, 0, SEEK_CUR)                   = -1 ESPIPE (Illegal seek)
close(0)                                = 0
close(1)                                = 0
close(2)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

HTH



More information about the Python-list mailing list