OSFS won't acknowledge the existence of symlinks if the symlink points to a non-existing destination:
>>> from fs import tempfs
>>> import os
>>> fs = tempfs.TempFS() # TempFS is a OSFS subclass
>>> src, dst = "foo", "bar"
>>> os.symlink(src, fs.getsyspath(dst)) # dst is the link, pointing to src
>>> fs.touch(src) # ensure that src exists
>>> fs.exists(dst) # fs acknowledges that dst exists
True
>>> fs.islink(dst) # and that dst is a link
True
>>> fs.remove(src) # but if we remove the src file
>>> os.path.islink(fs.getsyspath(dst)) # it is still a link
True
>>> fs.exists(dst) # but fs does not want to acknowledge it
False
>>> fs.islink(dst) # this raises, rather than return False
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../site-packages/fs/osfs.py", line 612, in islink
raise errors.ResourceNotFound(path)
fs.errors.ResourceNotFound: resource 'bar' not found
Note the exception thrown by fs.islink(); this goes counter to the behaviour of fs.isfile() and fs.isdir(), which both return False for this case.
First of all, I don't think fs.islink() should throw exceptions, it should return False if the path truly doesn't exist.
Now, I know that symlinks are a complex subject with miriad edge cases. Symlinks can point to other symlinks, or a parent directory of a path could be a symlink (e.g. realpath has -P / --physical, -L / -- logical modes that can lead to vastly different end results), etc. It could be that the intent is that only links that point to paths within the root of the filesystem are supported.
But the OSFS islink() documentation makes no mention of such restrictions, it simply claims to return True if the given path is a symlink on disk.
OSFS won't acknowledge the existence of symlinks if the symlink points to a non-existing destination:
Note the exception thrown by
fs.islink(); this goes counter to the behaviour offs.isfile()andfs.isdir(), which both returnFalsefor this case.First of all, I don't think
fs.islink()should throw exceptions, it should returnFalseif the path truly doesn't exist.Now, I know that symlinks are a complex subject with miriad edge cases. Symlinks can point to other symlinks, or a parent directory of a path could be a symlink (e.g.
realpathhas-P / --physical,-L / -- logicalmodes that can lead to vastly different end results), etc. It could be that the intent is that only links that point to paths within the root of the filesystem are supported.But the OSFS
islink()documentation makes no mention of such restrictions, it simply claims to return True if the given path is a symlink on disk.