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:
Steve Howell 2018-01-09 09:19:08 -05:00
parent e528577f11
commit 88f6ddefb2
2 changed files with 5 additions and 1 deletions

View file

@ -36,7 +36,11 @@ class TestVirtualFsBot(BotTestCase):
("", self.help_txt),
("pwd", "foo@example.com:\n/"),
("cd /home", "foo@example.com:\nERROR: invalid path"),
("mkdir etc", "foo@example.com:\ndirectory created"),
("mkdir home", "foo@example.com:\ndirectory created"),
("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)

View file

@ -252,7 +252,7 @@ def fs_rmdir(fs: Dict[str, Any], user: str, fn: str) -> Tuple[Dict[str, Any], An
new_fs.pop(path)
directory = get_directory(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+'/'):
new_fs.pop(sub_path)
msg = 'removed'