From 02890da7438571c1706c344e4ad6ac80950b3fbf Mon Sep 17 00:00:00 2001
From: David Stainton <dstainton415@gmail.com>
Date: Mon, 14 Sep 2015 12:41:12 +0200
Subject: [PATCH] Teach should_ignore_file to require unicode

---
 src/allmydata/magicpath.py           |  4 ++++
 src/allmydata/test/test_magicpath.py | 12 ++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/allmydata/magicpath.py b/src/allmydata/magicpath.py
index b072b463..ba15ed58 100644
--- a/src/allmydata/magicpath.py
+++ b/src/allmydata/magicpath.py
@@ -2,6 +2,8 @@
 import re
 import os.path
 
+from allmydata.util.assertutil import precondition
+
 def path2magic(path):
     return re.sub(ur'[/@]',  lambda m: {u'/': u'@_', u'@': u'@@'}[m.group(0)], path)
 
@@ -13,6 +15,8 @@ IGNORE_SUFFIXES = [u'.backup', u'.tmp', u'.conflicted']
 IGNORE_PREFIXES = [u'.']
 
 def should_ignore_file(path_u):
+    precondition(isinstance(path_u, unicode), path_u=path_u)
+
     for suffix in IGNORE_SUFFIXES:
         if path_u.endswith(suffix):
             return True
diff --git a/src/allmydata/test/test_magicpath.py b/src/allmydata/test/test_magicpath.py
index 2362bc3f..1227a2c4 100644
--- a/src/allmydata/test/test_magicpath.py
+++ b/src/allmydata/test/test_magicpath.py
@@ -20,9 +20,9 @@ class MagicPath(unittest.TestCase):
             self.failUnlessEqual(magicpath.magic2path(test), expected)
 
     def test_should_ignore(self):
-        self.failUnlessEqual(magicpath.should_ignore_file(".bashrc"), True)
-        self.failUnlessEqual(magicpath.should_ignore_file("bashrc."), False)
-        self.failUnlessEqual(magicpath.should_ignore_file("forest/tree/branch/.bashrc"), True)
-        self.failUnlessEqual(magicpath.should_ignore_file("forest/tree/.branch/bashrc"), True)
-        self.failUnlessEqual(magicpath.should_ignore_file("forest/.tree/branch/bashrc"), True)
-        self.failUnlessEqual(magicpath.should_ignore_file("forest/tree/branch/bashrc"), False)
+        self.failUnlessEqual(magicpath.should_ignore_file(u".bashrc"), True)
+        self.failUnlessEqual(magicpath.should_ignore_file(u"bashrc."), False)
+        self.failUnlessEqual(magicpath.should_ignore_file(u"forest/tree/branch/.bashrc"), True)
+        self.failUnlessEqual(magicpath.should_ignore_file(u"forest/tree/.branch/bashrc"), True)
+        self.failUnlessEqual(magicpath.should_ignore_file(u"forest/.tree/branch/bashrc"), True)
+        self.failUnlessEqual(magicpath.should_ignore_file(u"forest/tree/branch/bashrc"), False)
-- 
2.45.2