From b1e0dd66ebf75d58531a74f2346764c32b6ba8d5 Mon Sep 17 00:00:00 2001 From: Nick Lanham Date: Tue, 26 Apr 2011 13:53:11 +0200 Subject: [PATCH] handle files with [ and ] characters in them --- deluge/ui/console/modes/add_util.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/deluge/ui/console/modes/add_util.py b/deluge/ui/console/modes/add_util.py index bdd235e87..b741a6a11 100644 --- a/deluge/ui/console/modes/add_util.py +++ b/deluge/ui/console/modes/add_util.py @@ -43,7 +43,23 @@ import deluge.common import os,base64,glob +import logging +log = logging.getLogger(__name__) +def __bracket_fixup(path): + if (path.find("[") == -1 and + path.find("]") == -1): + return path + sentinal = 256 + while (path.find(unichr(sentinal)) != -1): + sentinal+=1 + if sentinal > 65535: + log.error("Can't fix brackets in path, path contains all possible sentinal characters") + return path + newpath = path.replace("]",unichr(sentinal)) + newpath = newpath.replace("[","[[]") + newpath = newpath.replace(unichr(sentinal),"[]]") + return newpath def add_torrent(t_file, options, success_cb, fail_cb, ress): t_options = {} @@ -57,7 +73,7 @@ def add_torrent(t_file, options, success_cb, fail_cb, ress): if is_url or is_mag: files = [t_file] else: - files = glob.glob(t_file) + files = glob.glob(__bracket_fixup(t_file)) num_files = len(files) ress["total"] = num_files