From b08da25d21d450ac1125a68e1bea628f32ff417e Mon Sep 17 00:00:00 2001 From: "DESKTOP-DPA61F8\\Benedek" Date: Mon, 26 Apr 2021 14:40:32 +0200 Subject: [PATCH] Test for MKD / RMD works like a charm --- server/authentication.py | 1 + server/executor.py | 14 ++++++++++---- server/server.py | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/server/authentication.py b/server/authentication.py index a066f5c..22a69dd 100644 --- a/server/authentication.py +++ b/server/authentication.py @@ -76,6 +76,7 @@ class Authetication: shutil.rmtree(self.HOME_DIRECTORY_LOCATION) os.mkdir(self.HOME_DIRECTORY_LOCATION) + os.mkdir(self.HOME_DIRECTORY_LOCATION + os.path.sep + '0') shutil.rmtree(self.PRIVATE_KEY_DIRECTORY_LOCATION) os.mkdir(self.PRIVATE_KEY_DIRECTORY_LOCATION) diff --git a/server/executor.py b/server/executor.py index 5c67947..2e131a1 100644 --- a/server/executor.py +++ b/server/executor.py @@ -2,17 +2,23 @@ import os import re +import sys class Executor: """This class executes commands recieved by the server""" + ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0])) + BASE_PATH = ABSOLUTE_PATH + os.path.sep + 'home' + os.path.sep + DEFAULT_FOLDER = BASE_PATH + '0' + def __init__(self, currentDiectory: str, baseDir: str = ""): self.currentDirectory = currentDiectory if baseDir == "": - self.baseDir = self.currentDirectory + self.baseDir = self.DEFAULT_FOLDER else: - self.baseDir = baseDir + self.baseDir = self.BASE_PATH + baseDir + os.path.sep + def sanitizeDirectory(self, inDirectory: str) -> str: return re.sub('[^a-zA-Z0-9]', '', inDirectory) @@ -22,13 +28,13 @@ class Executor: def createDirectory(self, dirName: str) -> str: dirName = self.sanitizeDirectory(dirName) - actualDirName = os.path.join(self.currentDirectory, dirName) + actualDirName: str = os.path.join(self.baseDir,self.currentDirectory,dirName) os.mkdir(actualDirName) return actualDirName def removeDirectory(self, dirName: str) -> str: dirName = self.sanitizeDirectory(dirName) - actualDirName = os.path.join(self.currentDirectory, dirName) + actualDirName: str = os.path.join(self.baseDir, self.currentDirectory, dirName) if actualDirName: os.rmdir(actualDirName) return actualDirName diff --git a/server/server.py b/server/server.py index 7a11b00..77c802b 100644 --- a/server/server.py +++ b/server/server.py @@ -21,13 +21,13 @@ class Server: def login(self, homeDir: str) -> None: self.isAuthenticated = True - self.executor.baseDir = Executor(homeDir) + self.executor = Executor("", homeDir) def logout(self) -> None: self.networkInstance.logout() self.isAuthenticated = False self.availableServer = False - self.executor.baseDir = Executor("") + self.executor = Executor("") def parseCommand(self, command: str) -> None: if command == "LINOK":