From 189a651f07f84e8d769e9544b45cc28b7498b2cd Mon Sep 17 00:00:00 2001 From: Michel Oosterhof Date: Thu, 15 Jan 2015 14:10:01 +0000 Subject: [PATCH] fix for exception on non-existent directory --- kippo/core/fs.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/kippo/core/fs.py b/kippo/core/fs.py index f6204ce7..060db1f2 100644 --- a/kippo/core/fs.py +++ b/kippo/core/fs.py @@ -86,12 +86,19 @@ class HoneyPotFilesystem(object): return found def get_path(self, path): - p = self.fs - for i in path.split('/'): - if not i: + cwd = self.fs + for part in path.split('/'): + if not len(part): continue - p = [x for x in p[A_CONTENTS] if x[A_NAME] == i][0] - return p[A_CONTENTS] + ok = False + for c in cwd[A_CONTENTS]: + if c[A_NAME] == part: + cwd = c + ok = True + break + if not ok: + return None + return cwd[A_CONTENTS] def exists(self, path): f = self.getfile(path) @@ -176,6 +183,8 @@ class HoneyPotFilesystem(object): if path == '/': return True dir = self.get_path(os.path.dirname(path)) + if dir is None: + return False l = [x for x in dir if x[A_NAME] == os.path.basename(path) and x[A_TYPE] == T_DIR]