From 4c253147724e863f5f9c0be5b9edad30d28402a9 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 8 Jul 2015 02:02:24 -0400 Subject: [PATCH] os.listdir returns str for non-latin filename, use unicode cast in path name to avoid this. Related to gh-issue #163. --- mayan/apps/sources/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mayan/apps/sources/models.py b/mayan/apps/sources/models.py index 421390bf30..6f6bf627e2 100644 --- a/mayan/apps/sources/models.py +++ b/mayan/apps/sources/models.py @@ -344,10 +344,11 @@ class WatchFolderSource(IntervalBaseModel): folder_path = models.CharField(max_length=255, verbose_name=_('Folder path'), help_text=_('Server side filesystem path.')) def check_source(self): - for file_name in os.listdir(self.folder_path): + # Force self.folder_path to unicode to avoid os.listdir returning + # str for non-latin filenames, gh-issue #163 + for file_name in os.listdir(unicode(self.folder_path)): full_path = os.path.join(self.folder_path, file_name) if os.path.isfile(full_path): - with File(file=open(full_path, mode='rb')) as file_object: self.upload_document(file_object, label=file_name, expand=(self.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y)) os.unlink(full_path)