Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
ad0675c8
Commit
ad0675c8
authored
Jan 15, 2010
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cross-directory rename() support for MemoryFS
parent
82223948
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
20 deletions
+32
-20
fs/memoryfs.py
+12
-15
fs/remote.py
+5
-5
fs/tests/__init__.py
+15
-0
No files found.
fs/memoryfs.py
View file @
ad0675c8
...
...
@@ -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
[
dir
name
]
parent_dir
.
name
=
dst
del
parent_dir
.
contents
[
dir
name
]
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
...
...
fs/remote.py
View file @
ad0675c8
...
...
@@ -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.
"""
...
...
fs/tests/__init__.py
View file @
ad0675c8
...
...
@@ -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!"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment