fix for exception on non-existent directory

This commit is contained in:
Michel Oosterhof 2015-01-15 14:10:01 +00:00
parent e9e09f949e
commit 189a651f07
1 changed files with 14 additions and 5 deletions

View File

@ -86,12 +86,19 @@ class HoneyPotFilesystem(object):
return found return found
def get_path(self, path): def get_path(self, path):
p = self.fs cwd = self.fs
for i in path.split('/'): for part in path.split('/'):
if not i: if not len(part):
continue continue
p = [x for x in p[A_CONTENTS] if x[A_NAME] == i][0] ok = False
return p[A_CONTENTS] 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): def exists(self, path):
f = self.getfile(path) f = self.getfile(path)
@ -176,6 +183,8 @@ class HoneyPotFilesystem(object):
if path == '/': if path == '/':
return True return True
dir = self.get_path(os.path.dirname(path)) dir = self.get_path(os.path.dirname(path))
if dir is None:
return False
l = [x for x in dir l = [x for x in dir
if x[A_NAME] == os.path.basename(path) and if x[A_NAME] == os.path.basename(path) and
x[A_TYPE] == T_DIR] x[A_TYPE] == T_DIR]