Commit cbcad9d0 by willmcgugan@gmail.com

Changed signature for 'createfile' everywhere, fixes #133

parent 7465c77a
...@@ -679,8 +679,8 @@ class CacheFSMixin(FS): ...@@ -679,8 +679,8 @@ class CacheFSMixin(FS):
self.__cache[path] = CachedInfo.new_file_stub() self.__cache[path] = CachedInfo.new_file_stub()
return res return res
def createfile(self, path): def createfile(self, path, wipe=False):
super(CacheFSMixin,self).createfile(path) super(CacheFSMixin,self).createfile(path, wipe=wipe)
with self.__cache_lock: with self.__cache_lock:
self.__cache.clear(path) self.__cache.clear(path)
self.__cache[path] = CachedInfo.new_file_stub() self.__cache[path] = CachedInfo.new_file_stub()
......
...@@ -136,6 +136,18 @@ class FSTestCases(object): ...@@ -136,6 +136,18 @@ class FSTestCases(object):
self.assertEquals(f.read(), b("test file overwrite")) self.assertEquals(f.read(), b("test file overwrite"))
f.close() f.close()
def test_createfile(self):
"""Test createfile"""
test = b('now with content')
self.fs.createfile("test.txt")
self.assert_(self.fs.exists("test.txt"))
self.assertEqual(self.fs.getcontents("test.txt", "rb"), b(''))
self.fs.setcontents("test.txt", test)
self.fs.createfile("test.txt")
self.assertEqual(self.fs.getcontents("test.txt", "rb"), test)
self.fs.createfile("test.txt", wipe=True)
self.assertEqual(self.fs.getcontents("test.txt", "rb"), b(''))
def test_setcontents(self): def test_setcontents(self):
# setcontents() should accept both a string... # setcontents() should accept both a string...
self.fs.setcontents("hello", b("world")) self.fs.setcontents("hello", b("world"))
...@@ -152,7 +164,7 @@ class FSTestCases(object): ...@@ -152,7 +164,7 @@ class FSTestCases(object):
b("to you, good sir!")), chunk_size=2) b("to you, good sir!")), chunk_size=2)
self.assertEquals(self.fs.getcontents( self.assertEquals(self.fs.getcontents(
"hello", "rb"), b("to you, good sir!")) "hello", "rb"), b("to you, good sir!"))
self.fs.setcontents("hello", "", "wb") self.fs.setcontents("hello", b"")
self.assertEquals(self.fs.getcontents("hello", "rb"), "") self.assertEquals(self.fs.getcontents("hello", "rb"), "")
def test_setcontents_async(self): def test_setcontents_async(self):
...@@ -888,7 +900,7 @@ class FSTestCases(object): ...@@ -888,7 +900,7 @@ class FSTestCases(object):
def test_zero_read(self): def test_zero_read(self):
"""Test read(0) returns empty string""" """Test read(0) returns empty string"""
self.fs.setcontents('foo.txt', b('Hello, World'), 'wb') self.fs.setcontents('foo.txt', b('Hello, World') )
with self.fs.open('foo.txt', 'rb') as f: with self.fs.open('foo.txt', 'rb') as f:
self.assert_(len(f.read(0)) == 0) self.assert_(len(f.read(0)) == 0)
with self.fs.open('foo.txt', 'rt') as f: with self.fs.open('foo.txt', 'rt') as f:
......
...@@ -323,9 +323,9 @@ class WatchableFS(WatchableFSMixin,WrapFS): ...@@ -323,9 +323,9 @@ class WatchableFS(WatchableFSMixin,WrapFS):
self.notify_watchers(MODIFIED, path, True) self.notify_watchers(MODIFIED, path, True)
return ret return ret
def createfile(self, path): def createfile(self, path, wipe=False):
existed = self.wrapped_fs.isfile(path) existed = self.wrapped_fs.isfile(path)
ret = super(WatchableFS, self).createfile(path) ret = super(WatchableFS, self).createfile(path, wipe=False)
if not existed: if not existed:
self.notify_watchers(CREATED,path) self.notify_watchers(CREATED,path)
self.notify_watchers(ACCESSED,path) self.notify_watchers(ACCESSED,path)
......
...@@ -167,8 +167,8 @@ class WrapFS(FS): ...@@ -167,8 +167,8 @@ class WrapFS(FS):
return super(WrapFS, self).setcontents(path, data, encoding=encoding, errors=errors, chunk_size=chunk_size) return super(WrapFS, self).setcontents(path, data, encoding=encoding, errors=errors, chunk_size=chunk_size)
@rewrite_errors @rewrite_errors
def createfile(self, path): def createfile(self, path, wipe=False):
return self.wrapped_fs.createfile(self._encode(path)) return self.wrapped_fs.createfile(self._encode(path), wipe=wipe)
@rewrite_errors @rewrite_errors
def exists(self, path): def exists(self, path):
......
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