use a platform agnostic way of combining paths in the FileTree

This commit is contained in:
Damien Churchill 2010-03-28 12:14:53 +01:00
parent 61b5659972
commit dd8400558c
2 changed files with 20 additions and 2 deletions

View File

@ -514,6 +514,24 @@ def is_ip(ip):
except socket.error:
return False
def path_join(*parts):
"""
An implementation of os.path.join that always uses / for the separator
to ensure that the correct paths are produced when working with internal
paths on Windows.
"""
path = ''
for part in parts:
if not part:
continue
elif part[0] == '/':
path = part
elif not path:
path = part
else:
path += '/' + part
return path
class VersionSplit(object):
"""
Used for comparing version numbers.

View File

@ -49,7 +49,7 @@ try:
except ImportError:
from sha import sha
from deluge import bencode
from deluge import bencode, common
from deluge.log import LOG as log
import deluge.configmanager
@ -289,7 +289,7 @@ class FileTree2(object):
"""
def walk(directory, parent_path):
for path in directory["contents"].keys():
full_path = os.path.join(parent_path, path)
full_path = common.path_join(parent_path, path)
if directory["contents"][path]["type"] == "dir":
directory["contents"][path] = callback(full_path, directory["contents"][path]) or \
directory["contents"][path]