From 4466ee617259ad0cc3b3bf497951972718be26c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Thu, 29 Apr 2021 17:33:15 +0200 Subject: [PATCH] use unipath --- requirements.txt | 3 ++- server/executor.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5da17aa..5187dab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pycryptodome -pydh \ No newline at end of file +pydh +unipath \ No newline at end of file diff --git a/server/executor.py b/server/executor.py index 985d0de..26245db 100644 --- a/server/executor.py +++ b/server/executor.py @@ -3,6 +3,8 @@ import os import re +from unipath import Path + class Executor: """This class executes commands recieved by the server""" @@ -34,16 +36,14 @@ class Executor: def setCurrentDirectory(self, dirName: str) -> str: if dirName == "..": - if self.currentDirectory == "": + p = Path(os.path.join(self.baseDir, self.currentDirectory)) + parentpath = p.parent + if str(parentpath) == self.baseDir: return self.currentDirectory else: - directories = self.currentDirectory.split(os.path.sep) - strdirectory = "" - for dir in directories: - strdirectory = os.path.join(strdirectory, dir) - strdirectory = strdirectory[:-3] - if os.path.exists(os.path.join(self.baseDir, self.currentDirectory)): - self.currentDirectory = strdirectory + newpath = str(parentpath).replace(self.baseDir,'') + if os.path.exists(os.path.join(self.baseDir,newpath)): + self.currentDirectory = newpath return self.currentDirectory else: dirName = self.sanitizeDirectory(dirName)