From 89b7b68dfe871c3e6be6d984c57e0135b52c9772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 18 Apr 2021 15:54:13 +0200 Subject: [PATCH] finito execturo for real --- server/executor.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/server/executor.py b/server/executor.py index 2da0185..e0340e5 100644 --- a/server/executor.py +++ b/server/executor.py @@ -36,10 +36,21 @@ class Executor: return self.currentDirectory def setCurrentDirectory(self, dirName: str) -> str: - # TODO : Navigate up a directory structure - dirName = self.sanitizeDirectory(dirName) - self.currentDirectory = self.currentDirectory + "/" + dirName - return self.currentDirectory + if dirName == "..": + if self.currentDirectory == self.baseDir: + return self.currentDirectory + else: + directories = self.currentDirectory.split("/") + strdirectory = "" + for dir in directories: + strdirectory += dir + "/" + strdirectory = strdirectory[:-3] + self.currentDirectory = strdirectory + return self.currentDirectory + else: + dirName = self.sanitizeDirectory(dirName) + self.currentDirectory = self.currentDirectory + "/" + dirName + return self.currentDirectory def listCurrentDirectoryContent(self) -> str: contents = os.listdir(self.currentDirectory) @@ -52,10 +63,10 @@ class Executor: def putFileInCurrentDirectory(self, filename: str, content) -> str: filename = self.sanitizeFile(filename) currenctfile = self.currentDirectory + "/" + filename - f = open(currenctfile,"wb") + f = open(currenctfile, "wb") f.write(content) f.close() - return currenctfile + return currenctfile def getFileInCurrentDirectory(self, file: str): file = self.sanitizeFile(file)