From dd8400558c20f8d30ffe0b81da0aac1847e5c632 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Sun, 28 Mar 2010 12:14:53 +0100 Subject: [PATCH] use a platform agnostic way of combining paths in the FileTree --- deluge/common.py | 18 ++++++++++++++++++ deluge/ui/common.py | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/deluge/common.py b/deluge/common.py index ab25b241e..fce4052dd 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -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. diff --git a/deluge/ui/common.py b/deluge/ui/common.py index 8acefd0ea..32872300c 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -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]