Skip to content

Commit 805d05d

Browse files
committed
XXX PROFOUND CHANGE: remove the assumption used in pyfs that path '' == '/'
1 parent 2df37d5 commit 805d05d

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ clean:
1717

1818
install:
1919
$(PYTHON) setup.py build
20-
$(PYTHON) setup.py develop
20+
$(PYTHON) setup.py develop --user
2121

2222
test: install
2323
$(PYTHON) $(TSCRIPT)

fs/mountfs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ def _delegate(self, path):
111111
else:
112112
head_path = prefix
113113
tail_path = path[len(head_path):]
114+
if tail_path == '':
115+
# XXX - GIAMPAOLO: I did this because pyfs methods (
116+
# makedir, listdir etc.) treat "" as an alias for "/",
117+
# which is stupid. We don't want to inherit this
118+
# assumption in our code and fill it with
119+
# "if path == '': path = '/'" all over the place
120+
# so we do it here.
121+
tail_path = '/'
114122

115123
if type(object) is MountFS.DirMount:
116124
return object.fs, head_path, tail_path

fs/tests/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ def test_meta(self):
8383
self.assertFalse(self.fs.hasmeta(meta_name))
8484

8585
def test_root_dir(self):
86-
self.assertTrue(self.fs.isdir(""))
8786
self.assertTrue(self.fs.isdir("/"))
8887
# These may be false (e.g. empty dict) but mustn't raise errors
89-
self.fs.getinfo("")
88+
self.fs.getinfo("/")
9089
self.assertTrue(self.fs.getinfo("/") is not None)
9190

9291
def test_getsyspath(self):
@@ -218,7 +217,7 @@ def check_unicode(items):
218217
self.assertEqual(len(d1), 4)
219218
self.assertEqual(sorted(d1), [u"a", u"b", u"bar", u"foo"])
220219
check_unicode(d1)
221-
d1 = self.fs.listdir("")
220+
d1 = self.fs.listdir("/")
222221
self.assertEqual(len(d1), 4)
223222
self.assertEqual(sorted(d1), [u"a", u"b", u"bar", u"foo"])
224223
check_unicode(d1)
@@ -283,7 +282,7 @@ def check_equal(items, target):
283282
self.assertEqual(len(d1), 4)
284283
check_equal(d1, [u"a", u"b", u"bar", u"foo"])
285284
check_unicode(d1)
286-
d1 = self.fs.listdirinfo("")
285+
d1 = self.fs.listdirinfo("/")
287286
self.assertEqual(len(d1), 4)
288287
check_equal(d1, [u"a", u"b", u"bar", u"foo"])
289288
check_unicode(d1)

fs/wrapfs/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ def isfile(self, path):
188188
return self.wrapped_fs.isfile(self._encode(path))
189189

190190
@rewrite_errors
191-
def listdir(self, path="", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
191+
def listdir(self, path="/", wildcard=None, full=False, absolute=False,
192+
dirs_only=False, files_only=False):
192193
kwds = dict(wildcard=wildcard,
193194
full=full,
194195
absolute=absolute,
@@ -242,7 +243,7 @@ def ilistdir(self, path="", wildcard=None, full=False, absolute=False, dirs_only
242243
yield e
243244

244245
@rewrite_errors
245-
def listdirinfo(self, path="", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
246+
def listdirinfo(self, path="/", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
246247
kwds = dict(wildcard=wildcard,
247248
full=full,
248249
absolute=absolute,

fs/wrapfs/hidefs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def exists(self, path):
4343
return False
4444
return super(HideFS, self).exists(path)
4545

46-
def listdir(self, path="", *args, **kwargs):
46+
def listdir(self, path="/", *args, **kwargs):
4747
entries = super(HideFS, self).listdir(path, *args, **kwargs)
4848
entries = [entry for entry in entries if not self._should_hide(entry)]
4949
return entries

0 commit comments

Comments
 (0)