Commit ad0675c8 by rfkelly0

cross-directory rename() support for MemoryFS

parent 82223948
......@@ -398,28 +398,25 @@ class MemoryFS(FS):
@synchronize
def rename(self, src, dst):
dst = pathsplit(dst)[-1]
dir_entry = self._get_dir_entry(src)
if dir_entry is None:
src_dir,src_name = pathsplit(src)
src_entry = self._get_dir_entry(src)
if src_entry is None:
raise ResourceNotFoundError(src)
#if dir_entry.islocked():
# raise ResourceLockedError(src)
open_files = dir_entry.open_files[:]
open_files = src_entry.open_files[:]
for f in open_files:
f.flush()
f.path = dst
dst_dir_entry = self._get_dir_entry(dst)
if dst_dir_entry is not None:
dst_dir,dst_name = pathsplit(dst)
dst_entry = self._get_dir_entry(dst)
if dst_entry is not None:
raise DestinationExistsError(path)
pathname, dirname = pathsplit(src)
parent_dir = self._get_dir_entry(pathname)
parent_dir.contents[dst] = parent_dir.contents[dirname]
parent_dir.name = dst
del parent_dir.contents[dirname]
src_dir_entry = self._get_dir_entry(src_dir)
dst_dir_entry = self._get_dir_entry(dst_dir)
dst_dir_entry.contents[dst_name] = src_dir_entry.contents[src_name]
dst_dir_entry.contents[dst_name].name = dst_name
del src_dir_entry.contents[src_name]
@synchronize
......
......@@ -9,15 +9,15 @@ Utilities for interfacing with remote filesystems
This module provides reusable utility functions that can be used to construct
FS subclasses interfacing with a remote filesystem. These include:
* RemoteFileBuffer: a file-like object that locally buffers the contents
of a remote file, writing them back on flush() or close().
* RemoteFileBuffer: a file-like object that locally buffers the contents of
a remote file, writing them back on flush() or close().
* ConnectionManagerFS: a WrapFS subclass that tracks the connection state
of a remote FS, and allows client code to wait for
a connection to be re-established.
of a remote FS, and allows client code to wait for
a connection to be re-established.
* CacheFS: a WrapFS subclass that caces file and directory meta-data in
memory, to speed access to a remote FS.
memory, to speed access to a remote FS.
"""
......
......@@ -239,11 +239,26 @@ class FSTestCases(object):
def test_rename(self):
check = self.check
# test renaming a file in the same directory
self.fs.createfile("foo.txt","Hello, World!")
self.assert_(check("foo.txt"))
self.fs.rename("foo.txt", "bar.txt")
self.assert_(check("bar.txt"))
self.assert_(not check("foo.txt"))
# test renaming a directory in the same directory
self.fs.makedir("dir_a")
self.fs.createfile("dir_a/test.txt","testerific")
self.assert_(check("dir_a"))
self.fs.rename("dir_a","dir_b")
self.assert_(check("dir_b"))
self.assert_(check("dir_b/test.txt"))
self.assert_(not check("dir_a/test.txt"))
self.assert_(not check("dir_a"))
# test renaming a file into a different directory
self.fs.makedir("dir_a")
self.fs.rename("dir_b/test.txt","dir_a/test.txt")
self.assert_(not check("dir_b/test.txt"))
self.assert_(check("dir_a/test.txt"))
def test_info(self):
test_str = "Hello, World!"
......
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