Commit f5c98904 by rfkelly0

Make listdirs(hidden=True) the default uniformly.

This was the case for all but OSFS and ZipFS, and it meant that copydir()
would not copy hidden files.  If this default isn't desired, walk() needs
to grow a hidden=True argument and copydir() needs to use it.
parent 0b1ccbd1
...@@ -56,7 +56,7 @@ class OSFS(FS): ...@@ -56,7 +56,7 @@ class OSFS(FS):
def ishidden(self, path): def ishidden(self, path):
return path.startswith('.') return path.startswith('.')
def listdir(self, path="./", wildcard=None, full=False, absolute=False, hidden=False, dirs_only=False, files_only=False): def listdir(self, path="./", wildcard=None, full=False, absolute=False, hidden=True, dirs_only=False, files_only=False):
try: try:
paths = os.listdir(self.getsyspath(path)) paths = os.listdir(self.getsyspath(path))
except (OSError, IOError), e: except (OSError, IOError), e:
......
...@@ -247,6 +247,7 @@ class TestOSFS(unittest.TestCase): ...@@ -247,6 +247,7 @@ class TestOSFS(unittest.TestCase):
self.assert_(check("foo.txt")) self.assert_(check("foo.txt"))
self.fs.rename("foo.txt", "bar.txt") self.fs.rename("foo.txt", "bar.txt")
self.assert_(check("bar.txt")) self.assert_(check("bar.txt"))
self.assert_(not check("foo.txt"))
def test_info(self): def test_info(self):
test_str = "Hello, World!" test_str = "Hello, World!"
...@@ -276,6 +277,7 @@ class TestOSFS(unittest.TestCase): ...@@ -276,6 +277,7 @@ class TestOSFS(unittest.TestCase):
f = self.fs.open(path, "rb") f = self.fs.open(path, "rb")
check_contents = f.read() check_contents = f.read()
f.close() f.close()
self.assertEqual(check_contents,contents)
return contents == check_contents return contents == check_contents
self.fs.makedir("foo/bar", recursive=True) self.fs.makedir("foo/bar", recursive=True)
...@@ -354,6 +356,28 @@ class TestOSFS(unittest.TestCase): ...@@ -354,6 +356,28 @@ class TestOSFS(unittest.TestCase):
self.assert_(check("a/3.txt")) self.assert_(check("a/3.txt"))
self.assert_(check("a/foo/bar/baz.txt")) self.assert_(check("a/foo/bar/baz.txt"))
def test_copydir_with_hidden(self):
check = self.check
contents = "If the implementation is hard to explain, it's a bad idea."
def makefile(path):
f = self.fs.open(path, "wb")
f.write(contents)
f.close()
self.fs.makedir("a")
makefile("a/1.txt")
makefile("a/2.txt")
makefile("a/.hidden.txt")
self.fs.makedir("copy of a")
self.fs.copydir("a", "copy of a")
self.assert_(check("copy of a/1.txt"))
self.assert_(check("copy of a/2.txt"))
self.assert_(check("copy of a/.hidden.txt"))
self.assert_(check("a/1.txt"))
self.assert_(check("a/2.txt"))
self.assert_(check("a/.hidden.txt"))
def test_readwriteappendseek(self): def test_readwriteappendseek(self):
def checkcontents(path, check_contents): def checkcontents(path, check_contents):
...@@ -364,6 +388,7 @@ class TestOSFS(unittest.TestCase): ...@@ -364,6 +388,7 @@ class TestOSFS(unittest.TestCase):
finally: finally:
if f is not None: if f is not None:
f.close() f.close()
self.assertEqual(read_contents,check_contents)
return read_contents == check_contents return read_contents == check_contents
test_strings = ["Beautiful is better than ugly.", test_strings = ["Beautiful is better than ugly.",
"Explicit is better than implicit.", "Explicit is better than implicit.",
...@@ -385,6 +410,7 @@ class TestOSFS(unittest.TestCase): ...@@ -385,6 +410,7 @@ class TestOSFS(unittest.TestCase):
f2 = self.fs.open("b.txt", "wb") f2 = self.fs.open("b.txt", "wb")
f2.write(test_strings[0]) f2.write(test_strings[0])
f2.close() f2.close()
self.assert_(checkcontents("b.txt", test_strings[0]))
f3 = self.fs.open("b.txt", "ab") f3 = self.fs.open("b.txt", "ab")
f3.write(test_strings[1]) f3.write(test_strings[1])
f3.write(test_strings[2]) f3.write(test_strings[2])
......
...@@ -201,7 +201,7 @@ class ZipFS(FS): ...@@ -201,7 +201,7 @@ class ZipFS(FS):
finally: finally:
self._lock.release() self._lock.release()
def listdir(self, path="/", wildcard=None, full=False, absolute=False, hidden=False, dirs_only=False, files_only=False): def listdir(self, path="/", wildcard=None, full=False, absolute=False, hidden=True, dirs_only=False, files_only=False):
return self._path_fs.listdir(path, wildcard, full, absolute, hidden, dirs_only, files_only) return self._path_fs.listdir(path, wildcard, full, absolute, hidden, dirs_only, files_only)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment