virtual_fs: Fix bug with "rmdir" command.
In python3, if you removed a directory that files within it, you would get an error saying "dictionary changed size during iteration." The fix is to list-ify the keys before iterating over them (and popping keys from the dictionary).
This commit is contained in:
parent
e528577f11
commit
88f6ddefb2
|
@ -36,7 +36,11 @@ class TestVirtualFsBot(BotTestCase):
|
||||||
("", self.help_txt),
|
("", self.help_txt),
|
||||||
("pwd", "foo@example.com:\n/"),
|
("pwd", "foo@example.com:\n/"),
|
||||||
("cd /home", "foo@example.com:\nERROR: invalid path"),
|
("cd /home", "foo@example.com:\nERROR: invalid path"),
|
||||||
|
("mkdir etc", "foo@example.com:\ndirectory created"),
|
||||||
("mkdir home", "foo@example.com:\ndirectory created"),
|
("mkdir home", "foo@example.com:\ndirectory created"),
|
||||||
("cd /home", "foo@example.com:\nCurrent path: /home/"),
|
("cd /home", "foo@example.com:\nCurrent path: /home/"),
|
||||||
|
("mkdir steve", "foo@example.com:\ndirectory created"),
|
||||||
|
("rmdir /home", "foo@example.com:\nremoved"),
|
||||||
|
("ls", "foo@example.com:\nERROR: file does not exist"),
|
||||||
]
|
]
|
||||||
self.verify_dialog(expected)
|
self.verify_dialog(expected)
|
||||||
|
|
|
@ -252,7 +252,7 @@ def fs_rmdir(fs: Dict[str, Any], user: str, fn: str) -> Tuple[Dict[str, Any], An
|
||||||
new_fs.pop(path)
|
new_fs.pop(path)
|
||||||
directory = get_directory(path)
|
directory = get_directory(path)
|
||||||
new_fs[directory]['fns'].remove(path)
|
new_fs[directory]['fns'].remove(path)
|
||||||
for sub_path in new_fs.keys():
|
for sub_path in list(new_fs.keys()):
|
||||||
if sub_path.startswith(path+'/'):
|
if sub_path.startswith(path+'/'):
|
||||||
new_fs.pop(sub_path)
|
new_fs.pop(sub_path)
|
||||||
msg = 'removed'
|
msg = 'removed'
|
||||||
|
|
Loading…
Reference in a new issue