Commit 2b2fbce1 by rfkelly0

support long paths (>> 260 chars) on win32

parent 974e63d7
#!/usr/bin/env python #!/usr/bin/env python
import os import os
import sys
from fs.base import * from fs.base import *
from fs.path import * from fs.path import *
...@@ -35,6 +36,9 @@ class OSFS(FS): ...@@ -35,6 +36,9 @@ class OSFS(FS):
def getsyspath(self, path, allow_none=False): def getsyspath(self, path, allow_none=False):
path = relpath(path).replace('/', os.sep) path = relpath(path).replace('/', os.sep)
sys_path = os.path.join(self.root_path, path) sys_path = os.path.join(self.root_path, path)
# Enable long pathnames on win32
if sys.platform == "win32":
sys_path = u"\\\\?\\" + os.path.abspath(sys_path)
return sys_path return sys_path
@convert_os_errors @convert_os_errors
......
#!/usr/bin/env python #!/usr/bin/env python
import os
from osfs import OSFS from osfs import OSFS
import tempfile import tempfile
from shutil import rmtree
class TempFS(OSFS): class TempFS(OSFS):
...@@ -37,7 +37,15 @@ class TempFS(OSFS): ...@@ -37,7 +37,15 @@ class TempFS(OSFS):
if not self._cleaned and self.exists("/"): if not self._cleaned and self.exists("/"):
self._lock.acquire() self._lock.acquire()
try: try:
rmtree(self._temp_dir) # shutil.rmtree doesn't handle long paths on win32,
# so we walk the tree by hand.
entries = os.walk(self.root_path,topdown=False)
for (dir,dirnames,filenames) in entries:
for filename in filenames:
os.remove(os.path.join(dir,filename))
for dirname in dirnames:
os.rmdir(os.path.join(dir,dirname))
os.rmdir(self.root_path)
self._cleaned = True self._cleaned = True
finally: finally:
self._lock.release() self._lock.release()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment