Skip to content

Commit

Permalink
XXX PROFOUND CHANGE: remove the assumption used in pyfs that path '' …
Browse files Browse the repository at this point in the history
…== '/'
  • Loading branch information
giampaolo committed May 19, 2016
1 parent 2df37d5 commit 805d05d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ clean:

install:
$(PYTHON) setup.py build
$(PYTHON) setup.py develop
$(PYTHON) setup.py develop --user

test: install
$(PYTHON) $(TSCRIPT)
8 changes: 8 additions & 0 deletions fs/mountfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ def _delegate(self, path):
else:
head_path = prefix
tail_path = path[len(head_path):]
if tail_path == '':
# XXX - GIAMPAOLO: I did this because pyfs methods (
# makedir, listdir etc.) treat "" as an alias for "/",
# which is stupid. We don't want to inherit this
# assumption in our code and fill it with
# "if path == '': path = '/'" all over the place
# so we do it here.
tail_path = '/'

if type(object) is MountFS.DirMount:
return object.fs, head_path, tail_path
Expand Down
7 changes: 3 additions & 4 deletions fs/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ def test_meta(self):
self.assertFalse(self.fs.hasmeta(meta_name))

def test_root_dir(self):
self.assertTrue(self.fs.isdir(""))
self.assertTrue(self.fs.isdir("/"))
# These may be false (e.g. empty dict) but mustn't raise errors
self.fs.getinfo("")
self.fs.getinfo("/")
self.assertTrue(self.fs.getinfo("/") is not None)

def test_getsyspath(self):
Expand Down Expand Up @@ -218,7 +217,7 @@ def check_unicode(items):
self.assertEqual(len(d1), 4)
self.assertEqual(sorted(d1), [u"a", u"b", u"bar", u"foo"])
check_unicode(d1)
d1 = self.fs.listdir("")
d1 = self.fs.listdir("/")
self.assertEqual(len(d1), 4)
self.assertEqual(sorted(d1), [u"a", u"b", u"bar", u"foo"])
check_unicode(d1)
Expand Down Expand Up @@ -283,7 +282,7 @@ def check_equal(items, target):
self.assertEqual(len(d1), 4)
check_equal(d1, [u"a", u"b", u"bar", u"foo"])
check_unicode(d1)
d1 = self.fs.listdirinfo("")
d1 = self.fs.listdirinfo("/")
self.assertEqual(len(d1), 4)
check_equal(d1, [u"a", u"b", u"bar", u"foo"])
check_unicode(d1)
Expand Down
5 changes: 3 additions & 2 deletions fs/wrapfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def isfile(self, path):
return self.wrapped_fs.isfile(self._encode(path))

@rewrite_errors
def listdir(self, path="", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
def listdir(self, path="/", wildcard=None, full=False, absolute=False,
dirs_only=False, files_only=False):
kwds = dict(wildcard=wildcard,
full=full,
absolute=absolute,
Expand Down Expand Up @@ -242,7 +243,7 @@ def ilistdir(self, path="", wildcard=None, full=False, absolute=False, dirs_only
yield e

@rewrite_errors
def listdirinfo(self, path="", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
def listdirinfo(self, path="/", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
kwds = dict(wildcard=wildcard,
full=full,
absolute=absolute,
Expand Down
2 changes: 1 addition & 1 deletion fs/wrapfs/hidefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def exists(self, path):
return False
return super(HideFS, self).exists(path)

def listdir(self, path="", *args, **kwargs):
def listdir(self, path="/", *args, **kwargs):
entries = super(HideFS, self).listdir(path, *args, **kwargs)
entries = [entry for entry in entries if not self._should_hide(entry)]
return entries
Expand Down

0 comments on commit 805d05d

Please sign in to comment.