From 8513d9ce2f7c57999233eb894c448a5d3b15cb90 Mon Sep 17 00:00:00 2001
From: lefthaha <lefthaha+dev@gmail.com>
Date: Sat, 7 Jun 2014 09:05:16 +0800
Subject: [PATCH] [#1109] Load torrents with special characters in autoadd dir
self.config["autoadd_location"] is a unicode string, but using
os.listdir(self.config["autoadd_location"]) will return a list of byte string
when some torrents contain non-ascii filename,it may raise UnicodeDecodeError
with os.pats.path.join(),to avoid messing around with encoding, directly using
byte string for file access
---
deluge/core/autoadd.py | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/deluge/core/autoadd.py b/deluge/core/autoadd.py
index 8d1219c..61d22d4 100644
|
a
|
b
|
def update(self):
|
| 73 | 73 | component.pause("AutoAdd") |
| 74 | 74 | return |
| 75 | 75 | |
| 76 | | for filename in os.listdir(self.config["autoadd_location"]): |
| | 76 | # Prevent unicode path join error, use byte string when accessing filename |
| | 77 | autoadd_dir = self.config["autoadd_location"] |
| | 78 | if isinstance(autoadd_dir, unicode): |
| | 79 | autoadd_dir = str(autoadd_dir) |
| | 80 | |
| | 81 | for filename in os.listdir(autoadd_dir): |
| 77 | 82 | try: |
| 78 | | filepath = os.path.join(self.config["autoadd_location"], filename) |
| 79 | | except UnicodeDecodeError, e: |
| | 83 | filepath = os.path.join(autoadd_dir, filename) |
| | 84 | except (UnicodeDecodeError, UnicodeEncodeError) as e: |
| 80 | 85 | log.error("Unable to auto add torrent due to improper filename encoding: %s", e) |
| 81 | 86 | continue |
| 82 | 87 | if os.path.isfile(filepath) and filename.endswith(".torrent"): |