From 88f6ddefb2ad1cc82b6ae0172b48ecbed7092584 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 9 Jan 2018 09:19:08 -0500 Subject: [PATCH] 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). --- zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py | 4 ++++ zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py b/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py index ec85cd6..72c2aab 100755 --- a/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py +++ b/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py @@ -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) diff --git a/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py b/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py index 0e72a4d..35fe4fd 100644 --- a/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py +++ b/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py @@ -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'