[Python-ideas] shutil.symlink to allow non-race replacement of existing link targets
Serhiy Storchaka
storchaka at gmail.com
Tue May 14 07:43:03 EDT 2019
13.05.19 12:38, Tom Hale пише:
> As suggested by Toshio Kuratomi at https://bugs.python.org/issue36656, I
> am raising this here for inclusion in the shutil module.
>
> Mimicking POSIX, os.symlink() will raise FileExistsError if the link
> name to be created already exists.
>
> A common use case is overwriting an existing file (often a symlink) with
> a symlink. Naively, one would delete the file named link_name file if it
> exists, then call symlink(). This "solution" is already 3 lines of code,
> and without exception handling it introduces the race condition of a
> file named link_name being created between unlink and symlink.
>
> Depending on the functionality required, I suggest:
>
> * os.symlink() - the new link name is expected to NOT exist
> * shutil.symlink() - the new symlink replaces an existing file
Sorry, but I do not understand what problem do you try to solve. If
somebody can create a file named link_name between unlink and symlink,
he can also remove and create a file named link_name after symlink.
More information about the Python-ideas
mailing list