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
a534d7d3
Commit
a534d7d3
authored
Feb 16, 2010
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure that rename() raises ParentDirectoryMissingError when appropriate
parent
52f3de1a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
5 deletions
+25
-5
fs/ftpfs.py
+7
-0
fs/memoryfs.py
+2
-0
fs/osfs.py
+12
-5
fs/sftpfs.py
+2
-0
fs/tests/__init__.py
+2
-0
No files found.
fs/ftpfs.py
View file @
a534d7d3
...
...
@@ -927,6 +927,8 @@ class FTPFS(FS):
code
=
int
(
code
)
if
code
==
550
:
raise
ResourceNotFoundError
(
path
)
if
code
==
552
:
raise
StorageSpaceError
raise
PermissionDeniedError
(
str
(
exception
),
path
=
path
,
msg
=
"FTP error:
%
s (see details)"
%
str
(
exception
),
details
=
exception
)
raise
exception
...
...
@@ -1067,6 +1069,11 @@ class FTPFS(FS):
self
.
clear_dircache
(
dirname
(
src
),
dirname
(
dst
),
src
,
dst
)
try
:
self
.
ftp
.
rename
(
_encode
(
src
),
_encode
(
dst
))
except
error_perm
,
exception
:
code
,
message
=
str
(
exception
)
.
split
(
' '
,
1
)
if
code
==
"550"
:
if
not
self
.
exists
(
dirname
(
dst
)):
raise
ParentDirectoryMissingError
(
dst
)
except
error_reply
:
pass
...
...
fs/memoryfs.py
View file @
a534d7d3
...
...
@@ -414,6 +414,8 @@ class MemoryFS(FS):
src_dir_entry
=
self
.
_get_dir_entry
(
src_dir
)
dst_dir_entry
=
self
.
_get_dir_entry
(
dst_dir
)
if
dst_dir_entry
is
None
:
raise
ParentDirectoryMissingError
(
dst
)
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
]
...
...
fs/osfs.py
View file @
a534d7d3
...
...
@@ -180,11 +180,18 @@ class OSFS(FS):
try
:
os
.
rename
(
path_src
,
path_dst
)
except
OSError
,
e
:
# Linux (at least) can rename over an empty directory but gives
# ENOTEMPTY if the dir has contents. Raise UnsupportedError
# instead of DirectoryEmptyError in this case.
if
e
.
errno
and
e
.
errno
==
errno
.
ENOTEMPTY
:
raise
UnsupportedError
(
"rename"
)
if
e
.
errno
:
# POSIX rename() can rename over an empty directory but gives
# ENOTEMPTY if the dir has contents. Raise UnsupportedError
# instead of DirectoryEmptyError in this case.
if
e
.
errno
==
errno
.
ENOTEMPTY
:
raise
UnsupportedError
(
"rename"
)
# Linux (at least) gives ENOENT when trying to rename into
# a directory that doesn't exist. We want ParentMissingError
# in this case.
if
e
.
errno
==
errno
.
ENOENT
:
if
not
os
.
path
.
exists
(
dirname
(
path_dst
)):
raise
ParentDirectoryMissingError
(
dst
)
raise
...
...
fs/sftpfs.py
View file @
a534d7d3
...
...
@@ -263,6 +263,8 @@ class SFTPFS(FS):
except
IOError
,
e
:
if
getattr
(
e
,
"errno"
,
None
)
==
2
:
raise
ResourceNotFoundError
(
path
)
if
not
self
.
isdir
(
dirname
(
dst
)):
raise
ParentDirectoryMissingError
(
dst
)
raise
@convert_os_errors
...
...
fs/tests/__init__.py
View file @
a534d7d3
...
...
@@ -259,6 +259,8 @@ class FSTestCases(object):
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"
))
# test renaming a file into a non-existent directory
self
.
assertRaises
(
ParentDirectoryMissingError
,
self
.
fs
.
rename
,
"dir_a/test.txt"
,
"nonexistent/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