PyFilesystem / pyfilesystem

Python filesystem abstraction layer
http://pyfilesystem.org/
BSD 3-Clause "New" or "Revised" License
288 stars 63 forks source link

simple open fails on Windows #143

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Attempt to open a simple file on the file system and you get a PathError:

>>> import fs.osfs
>>> fs_ = fs.osfs.OSFS('C:\\')
>>> fs_.open('C:\\foo.txt')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "fs-0.4.0-py2.7.egg\fs\errors.py", line 229, in wrapper
    return func(self,*args,**kwds)
  File "fs-0.4.0-py2.7.egg\fs\osfs\__init__.py", line 209, in open
    sys_path = self.getsyspath(path)
  File "fs-0.4.0-py2.7.egg\fs\osfs\__init__.py", line 149, in getsyspath
    raise PathError(path,msg="OSFS given path outside root: %(path)s")
fs.errors.PathError: OSFS given path outside root: C:\foo.txt

Running a debugger reveals the underlying issue, namely that in 
osfs/__init__.py:149 in getsyspath, root_path is u'\\\\?\\C:\\', so the test 
path.startswith(self.root_path) fails.

Since pyfs added the \\?\ prefix, the routine should be aware of the \\?\ 
prefix and account for it when checking for containment.

This is fs 0.4.0 on Windows 8 64-bit.

Original issue reported on code.google.com by jar...@jaraco.com on 30 Dec 2012 at 10:51

GoogleCodeExporter commented 9 years ago
FS objects, once constructed, don't take system paths. Please see the 
documentation:

http://packages.python.org/fs/concepts.html#paths

In your example, this is what you want:

    fs.open('foo.txt')

Original comment by willmcgugan on 30 Dec 2012 at 11:48

GoogleCodeExporter commented 9 years ago
Aha! I encountered this problem maintaining a project which is apparently 
incorrectly using pyfs (keyring).

Thanks for the clarification.

Original comment by jar...@jaraco.com on 30 Dec 2012 at 4:34