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.
This commit is contained in:
parent
7bfaeec54c
commit
72486f6371
|
@ -89,6 +89,7 @@ def sample_conversation():
|
||||||
('read /bar', 'new bar'),
|
('read /bar', 'new bar'),
|
||||||
('write /yo/invalid whatever', 'ERROR: /yo is not a directory'),
|
('write /yo/invalid whatever', 'ERROR: /yo is not a directory'),
|
||||||
('mkdir /yo', 'directory created'),
|
('mkdir /yo', 'directory created'),
|
||||||
|
('read /yo', 'ERROR: /yo is a directory, file required'),
|
||||||
('ls /yo', 'WARNING: directory is empty'),
|
('ls /yo', 'WARNING: directory is empty'),
|
||||||
('read /yo/nada', 'ERROR: file does not exist'),
|
('read /yo/nada', 'ERROR: file does not exist'),
|
||||||
('write /yo whatever', 'ERROR: file already exists'),
|
('write /yo whatever', 'ERROR: file already exists'),
|
||||||
|
@ -210,6 +211,9 @@ def fs_read(fs, fn):
|
||||||
if fn not in fs:
|
if fn not in fs:
|
||||||
msg = 'ERROR: file does not exist'
|
msg = 'ERROR: file does not exist'
|
||||||
return fs, msg
|
return fs, msg
|
||||||
|
if fs[fn]['kind'] == 'dir':
|
||||||
|
msg = 'ERROR: {} is a directory, file required'.format(fn)
|
||||||
|
return fs, msg
|
||||||
val = fs[fn]['content']
|
val = fs[fn]['content']
|
||||||
return fs, val
|
return fs, val
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue