[Python-ideas] os.path.cansymlink(path)

anatoly techtonik techtonik at gmail.com
Fri Jul 25 12:17:13 CEST 2014


On Thu, Jul 24, 2014 at 8:53 PM,  <dw+python-ideas at hmmz.org> wrote:
> On Thu, Jul 24, 2014 at 01:33:28PM -0400, Geoffrey Spear wrote:
>
>> > This code is wrong, because OS support for symlinks doesn't
>> > guarantee that mounted filesystem can do this, resulting in OSError
>> > at runtime. So, the proper check would be to check if specific path
>> > supports symlinking.
>> >
>> > The idea is:
>> >
>> >     os.path.cansymlink(path)  - Return True if filesystem
>> >         of specified path can be symlinked.
>> >
>> > Yes/No/Opinions?
>
> -1, since there is no sane way to guarantee a FS operation will succeed
> without trying it in most cases.
>
>  Even if a filesystem (driver) supports
> the operation, the filesystem (data) might be exhausted, e.g. inode
> count, max directory entries, ... And if not that, then e.g. in the case
> of NFS or CIFS, while the protocol might support the operation, there is
> no mechanism for a particular server implementation to communicate that
> it does not support it.

You do realize that high level program logic changes depending on the fact
that FS supports symlinks or not. It is not "an exceptional" case as you've
presented it.

This is not a replacement for os.symlink(), but doc link to this function will
help people avoid this trap and runtime errors in future.
-- 
anatoly t.


More information about the Python-ideas mailing list