Let me prefix all of this by saying that a shutil.symlink_with_overwrite is useful (see below), but limited in scope.

Please see my next post on emulating POSIX ln.

On 16/5/19 2:02 pm, Serhiy Storchaka wrote:

This may be an interesting project on PyPi, but I do not think that we need to include it in the stdlib. Because of little need and because of complex errorprone implementation.

There are two points here.  1) Need.  2) Implementation difficulty.

1. Need

The reason I believe that this code should be available in a standard library is that it's unreasonable to expect that the average user who wishes to replace a symlink (or hard link for that matter) to work out the possible ways in which the operation could go wrong, and then correctly prevent those non-obvious failure cases.

Yes, the likelihood of link_name being created (or not being removed) between unlink and (sym)link is *extremely* low, but it is NOT zero.

Also, the likelihood of a needed symlink being accessed between unlink and link is tiny.

Given that the the first case likelihood is so low, most users won't bother to roll their own robust solution, and instead just lazily cross their fingers and hope. Even if they do try to avoid the first race mentioned above, the most obvious solution still contains the 2nd race, as shown in my OP.

There is a known non-trivial solution for a known problem which is a type of problem that many people would not think about. In my opinion, shielding users from needing to know and work through all of this is worthwhile and responsible. Indeed, it may be part of a duty of care, following the "no surprises" rule of thumb.


2. Difficulty of implementation

Increased difficulty of implementation would mean that the code is more likely be implemented poorly/incorrectly on a roll-your-own basis. To me, I see this as adding weight to the case of inclusion in a library.

--
Tom Hale
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to