From 72486f637175ed9dee909042b6022a2c5ac0ba34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Thu, 12 Jan 2017 15:14:28 +0000 Subject: [PATCH] Fix virtual_fs bot trying to read a directory This commit prevents the bot from crashing when a command like 'fs read /home' is entered. Instead, an error is displayed. --- contrib_bots/lib/virtual_fs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib_bots/lib/virtual_fs.py b/contrib_bots/lib/virtual_fs.py index 21d1004..911293d 100644 --- a/contrib_bots/lib/virtual_fs.py +++ b/contrib_bots/lib/virtual_fs.py @@ -89,6 +89,7 @@ def sample_conversation(): ('read /bar', 'new bar'), ('write /yo/invalid whatever', 'ERROR: /yo is not a directory'), ('mkdir /yo', 'directory created'), + ('read /yo', 'ERROR: /yo is a directory, file required'), ('ls /yo', 'WARNING: directory is empty'), ('read /yo/nada', 'ERROR: file does not exist'), ('write /yo whatever', 'ERROR: file already exists'), @@ -210,6 +211,9 @@ def fs_read(fs, fn): if fn not in fs: msg = 'ERROR: file does not exist' return fs, msg + if fs[fn]['kind'] == 'dir': + msg = 'ERROR: {} is a directory, file required'.format(fn) + return fs, msg val = fs[fn]['content'] return fs, val