[Python-ideas] Have os.unlink remove directories on Unix (was: junction points on Windows)

random832 at fastmail.us random832 at fastmail.us
Mon Aug 26 14:25:55 CEST 2013


On Mon, Aug 26, 2013, at 7:42, Kim Gräsman wrote:
> I wouldn't switch to using os.rmdir, however -- if the path names an
> actual directory rather than a symlink or a junction point, os.rmdir
> will delete it, whereas os.unlink will fail with access denied (as I
> believe it should.)

Only if it's empty. You could at least replace whatever your
_delete_junction_point function is with it.

> > While we're on the subject of os.remove, can someone explain to me why
> > it doesn't work on directories in Unix? [...]
> 
> I have nothing to offer here, sorry. It seems a little dangerous to
> muck about with the details of os file management, there must be
> millions of lines of code relying on the current behavior in one way
> or another.

I just don't like the fact that it's called "remove" but doesn't behave
the same as the remove function from POSIX. Of course, remove/_wremove
do not remove directories on Windows, and I've found evidence that this
was true for some early Unixes as well. And the fact that windows
unlink() allows you to remove some (but not all) things that windows
considers to be directories is already violating the principle of being
thin wrappers around system calls.


More information about the Python-ideas mailing list