summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwillmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f>2010-06-17 13:43:40 +0000
committerwillmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f>2010-06-17 13:43:40 +0000
commit55dd394e23785048a0a3957ac2887ed8a90f0901 (patch)
tree68cd56f56e14faeb0174df2ea2619f84efae2421
parent043da7d644579f11b63023ef2dcb50995fc07ccb (diff)
downloadpyfilesystem-git-55dd394e23785048a0a3957ac2887ed8a90f0901.tar.gz
Some fixes to improve fuse support
-rw-r--r--fs/memoryfs.py36
1 files changed, 28 insertions, 8 deletions
diff --git a/fs/memoryfs.py b/fs/memoryfs.py
index f489806..ded2a1a 100644
--- a/fs/memoryfs.py
+++ b/fs/memoryfs.py
@@ -3,9 +3,10 @@
fs.memoryfs
===========
-A Filesystem that exists in memory only.
+A Filesystem that exists in memory only. Which makes them extremely fast, but non-permanent.
+
+If you open a file from a `memoryfs` you will get back a StringIO object from the standard library.
-File objects returned by MemoryFS.objects use StringIO objects for storage.
"""
@@ -37,7 +38,12 @@ class MemoryFile(object):
self.mem_file = None
- if _check_mode(mode, 'wa'):
+ if '+' in mode:
+ self.mem_file = StringIO()
+ self.mem_file.write(value)
+ self.mem_file.seek(0)
+
+ elif _check_mode(mode, 'wa'):
self.mem_file = StringIO()
self.mem_file.write(value)
@@ -50,6 +56,7 @@ class MemoryFile(object):
elif _check_mode(mode, 'r'):
self.mem_file = StringIO(value)
+ self.mem_file.seek(0)
elif _check_mode(mode, "a"):
self.mem_file = StringIO()
@@ -153,9 +160,9 @@ class DirEntry(object):
def desc_contents(self):
if self.isfile():
- return "<file %s>"%self.name
+ return "<file %s>" % self.name
elif self.isdir():
- return "<dir %s>"%"".join( "%s: %s"% (k, v.desc_contents()) for k, v in self.contents.iteritems())
+ return "<dir %s>" % "".join( "%s: %s"% (k, v.desc_contents()) for k, v in self.contents.iteritems())
def isdir(self):
return self.type == "dir"
@@ -172,9 +179,7 @@ class DirEntry(object):
class MemoryFS(FS):
- """ An in-memory filesystem.
-
- MemoryFS objects are very fast, but non-permantent. They are useful for creating a directory structure prior to writing it somewhere permanent.
+ """An in-memory filesystem.
"""
@@ -428,6 +433,21 @@ class MemoryFS(FS):
del src_dir_entry.contents[src_name]
+ def settimes(self, path, accessed_time=None, modified_time=None):
+ now = datetime.datetime.now()
+ if accessed_time is None:
+ accessed_time = now
+ if modified_time is None:
+ modified_time = now
+
+ dir_entry = self._get_dir_entry(path)
+ if dir_entry is not None:
+ dir_entry.accessed_time = accessed_time
+ dir_entry.modified_time = modified_time
+ return True
+ return False
+
+
@synchronize
def _on_close_memory_file(self, open_file, path, value):
filepath, filename = pathsplit(path)