Commit 5fa19265 by rfkelly0

OSFS: don't let removedirs() recurse beyond the FS root

parent 52a5eaad
...@@ -103,17 +103,20 @@ class OSFS(FS): ...@@ -103,17 +103,20 @@ class OSFS(FS):
def removedir(self, path, recursive=False): def removedir(self, path, recursive=False):
sys_path = self.getsyspath(path) sys_path = self.getsyspath(path)
# Don't remove the root directory of this FS
if path in ("","/"):
return
try:
os.rmdir(sys_path)
except OSError, e:
raise OperationFailedError("REMOVEDIR_FAILED", path, details=e)
# Using os.removedirs() for this can result in dirs being
# removed outside the root of this FS, so we recurse manually.
if recursive: if recursive:
try: try:
os.removedirs(sys_path) self.removedir(dirname(path),recursive=True)
except OSError, e: except OperationFailedError:
raise OperationFailedError("REMOVEDIR_FAILED", path, details=e) pass
else:
try:
os.rmdir(sys_path)
except OSError, e:
raise OperationFailedError("REMOVEDIR_FAILED", path, details=e)
def rename(self, src, dst): def rename(self, src, dst):
if not issamedir(src, dst): if not issamedir(src, dst):
......
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