File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change 1212from .copy import copy_file , copy_dir
1313from .info import Info
1414from .move import move_file , move_dir
15- from .path import abspath , normpath
15+ from .path import abspath , join , normpath
1616from .error_tools import unwrap_errors
1717
1818if typing .TYPE_CHECKING :
@@ -217,11 +217,20 @@ def removetree(self, dir_path):
217217 # type: (Text) -> None
218218 self .check ()
219219 _path = abspath (normpath (dir_path ))
220- if _path == "/" :
221- raise errors .RemoveRootError ()
222- _fs , _path = self .delegate_path (dir_path )
220+ _delegate_fs , _delegate_path = self .delegate_path (dir_path )
223221 with unwrap_errors (dir_path ):
224- _fs .removetree (_path )
222+ if _path == "/" :
223+ # with root path, we must remove the contents but
224+ # not the directory itself, so we can't just directly
225+ # delegate
226+ for info in _delegate_fs .scandir (_delegate_path ):
227+ info_path = join (_delegate_path , info .name )
228+ if info .is_dir :
229+ _delegate_fs .removetree (info_path )
230+ else :
231+ _delegate_fs .remove (info_path )
232+ else :
233+ _delegate_fs .removetree (_delegate_path )
225234
226235 def scandir (
227236 self ,
You can’t perform that action at this time.
0 commit comments