Commit 5c373200 by rfkelly0

OSFS: allow removdir(force=True) to empty root directory, but not delete it

parent c37d4a12
...@@ -88,14 +88,14 @@ class OSFS(FS): ...@@ -88,14 +88,14 @@ class OSFS(FS):
@convert_os_errors @convert_os_errors
def removedir(self, path, recursive=False,force=False): def removedir(self, path, recursive=False,force=False):
sys_path = self.getsyspath(path) sys_path = self.getsyspath(path)
# Don't remove the root directory of this FS
if path in ("","/"):
return
if force: if force:
for path2 in self.listdir(path,absolute=True,files_only=True): for path2 in self.listdir(path,absolute=True,files_only=True):
self.remove(path2) self.remove(path2)
for path2 in self.listdir(path,absolute=True,dirs_only=True): for path2 in self.listdir(path,absolute=True,dirs_only=True):
self.removedir(path2,force=True) self.removedir(path2,force=True)
# Don't remove the root directory of this FS
if path in ("","/"):
return
os.rmdir(sys_path) os.rmdir(sys_path)
# Using os.removedirs() for this can result in dirs being # Using os.removedirs() for this can result in dirs being
# removed outside the root of this FS, so we recurse manually. # removed outside the root of this FS, so we recurse manually.
......
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