[Python-ideas] os.path.cansymlink(path)
Oleg Broytman
phd at phdru.name
Fri Jul 25 12:23:40 CEST 2014
Hi!
On Thu, Jul 24, 2014 at 07:51:08PM +0300, anatoly techtonik <techtonik at gmail.com> wrote:
> This is a live code from current virtualenv.py:
>
> if hasattr(os, 'symlink'):
> logger.info('Symlinking Python bootstrap modules')
>
> 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?
Such function (if it would be a function) should return one of three
answer, not two. Something like:
None - I don't know if the OS/fs support symlinks because another
OSError occurred during test (perhaps not enough rights to write
to the path);
False- the path clearly doesn't support symlinks;
True - the path positively supports symlinks.
Implement the function in a module and publish the module at PyPI.
Warn users (in accompanying docs) that even if a path supports (or
doesn't support) symlinks this says nothing about any subpath of the
path because a subpath can be a mount of a different fs.
Oleg.
--
Oleg Broytman http://phdru.name/ phd at phdru.name
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-ideas
mailing list