From 9274820511013c48b45a6654f76c5360f72f3551 Mon Sep 17 00:00:00 2001 From: "willmcgugan@gmail.com" Date: Tue, 10 Sep 2013 00:10:53 +0000 Subject: createfile fixes git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@876 67cdc799-7952-0410-af00-57a81ceafa0f --- fs/base.py | 18 +++++++++--------- fs/path.py | 2 ++ fs/remote.py | 1 + fs/tests/test_remote.py | 3 +++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/fs/base.py b/fs/base.py index c1c363d..8e2686e 100644 --- a/fs/base.py +++ b/fs/base.py @@ -895,15 +895,15 @@ class FS(object): :param wipe: if True, the contents of the file will be erased """ - if not wipe and self.isfile(path): - return - - f = None - try: - f = self.open(path, 'w') - finally: - if f is not None: - f.close() + with self._lock: + if not wipe and self.isfile(path): + return + f = None + try: + f = self.open(path, 'wb') + finally: + if f is not None: + f.close() def opendir(self, path): """Opens a directory and returns a FS object representing its contents. diff --git a/fs/path.py b/fs/path.py index 31bb4c3..67aa481 100644 --- a/fs/path.py +++ b/fs/path.py @@ -192,6 +192,8 @@ def pathcombine(path1, path2): 'foo/bar/baz' """ + if not path1: + return path2.lstrip() return "%s/%s" % (path1.rstrip('/'), path2.lstrip('/')) diff --git a/fs/remote.py b/fs/remote.py index 1ac502b..86829c9 100644 --- a/fs/remote.py +++ b/fs/remote.py @@ -103,6 +103,7 @@ class RemoteFileBuffer(FileWrapper): # Do not use remote file object self._eof = True self._rfile = None + self._changed = True if rfile is not None and hasattr(rfile,"close"): rfile.close() super(RemoteFileBuffer,self).__init__(wrapped_file,mode) diff --git a/fs/tests/test_remote.py b/fs/tests/test_remote.py index 9a4db5e..4a21e3f 100644 --- a/fs/tests/test_remote.py +++ b/fs/tests/test_remote.py @@ -30,6 +30,9 @@ class RemoteTempFS(TempFS): Simple filesystem implementing setfilecontents for RemoteFileBuffer tests """ + def __repr__(self): + return '' % self._temp_dir + def open(self, path, mode='rb', write_on_flush=True, **kwargs): if 'a' in mode or 'r' in mode or '+' in mode: f = super(RemoteTempFS, self).open(path, mode='rb', **kwargs) -- cgit v1.2.1