From 822995981e33afaf712b051a995543032b17b7c8 Mon Sep 17 00:00:00 2001 From: RPJosh Date: Tue, 11 Oct 2022 19:38:44 +0200 Subject: [PATCH] Fix login on first startup and logout crash --- src/api/webDAV.cpp | 19 +++++++++++++------ src/handler/eventHandler.cpp | 2 +- src/handler/fileHandler.cpp | 1 - 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/api/webDAV.cpp b/src/api/webDAV.cpp index 0f5d6f1..92cb713 100644 --- a/src/api/webDAV.cpp +++ b/src/api/webDAV.cpp @@ -33,7 +33,12 @@ std::string WebDAV::getRootPath(bool encode) { if (rootPath == "") rootPath += "/"; - string rtc = NEXTCLOUD_ROOT_PATH + Util::getConfig("UUID", "") + rootPath; + string user = Util::getConfig("UUID", ""); + if (user == "") + user = Util::getConfig("username", "error"); + + string rtc = NEXTCLOUD_ROOT_PATH + user + rootPath; + if (encode) { Util::encodeUrl(rtc); rtc = std::regex_replace(rtc, std::regex("%2F"), "/"); @@ -44,6 +49,8 @@ std::string WebDAV::getRootPath(bool encode) { WebDAV::WebDAV() { + _fileHandler = std::shared_ptr(new FileHandler()); + if (iv_access(NEXTCLOUD_PATH.c_str(), W_OK) != 0) iv_mkdir(NEXTCLOUD_PATH.c_str(), 0777); @@ -53,7 +60,6 @@ WebDAV::WebDAV() _password = Util::accessConfig(Action::IReadSecret,"password",{}); _url = Util::accessConfig(Action::IReadString, "url",{}); _ignoreCert = Util::accessConfig(Action::IReadInt, "ignoreCert",{}); - _fileHandler = std::shared_ptr(new FileHandler()); } } @@ -108,7 +114,9 @@ void WebDAV::logout(bool deleteFiles) { if (deleteFiles) { - fs::remove_all(Util::accessConfig(Action::IReadString, "storageLocation",{}) + "/" + Util::accessConfig(Action::IReadString,"UUID",{}) + '/'); + string filesPath = Util::accessConfig(Action::IReadString, "storageLocation",{}) + "/" + Util::accessConfig(Action::IReadString,"UUID",{}) + '/'; + if (fs::exists(filesPath)) + fs::remove_all(filesPath); } fs::remove(CONFIG_PATH.c_str()); fs::remove((CONFIG_PATH + ".back.").c_str()); @@ -201,8 +209,8 @@ vector WebDAV::getDataStructure(const string &pathUrl) string pathDecoded = tempItem.path; Util::decodeUrl(pathDecoded); - tempItem.hide = _fileHandler->getHideState(tempItem.type, prefix,(pathDecoded), tempItem.title); - + tempItem.hide = _fileHandler->getHideState(tempItem.type, prefix,pathDecoded, tempItem.title); + tempItems.push_back(tempItem); xmlItem = xmlItem.substr(end + endItem.length()); begin = xmlItem.find(beginItem); @@ -248,7 +256,6 @@ string WebDAV::propfind(const string &pathUrl) string readBuffer; CURLcode res; CURL *curl = curl_easy_init(); - Log::writeInfoLog("Path: " + pathUrl); if (curl) { diff --git a/src/handler/eventHandler.cpp b/src/handler/eventHandler.cpp index 74bf423..b352e7b 100644 --- a/src/handler/eventHandler.cpp +++ b/src/handler/eventHandler.cpp @@ -432,7 +432,7 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2) { ShowHourglassForce(); - std::vector currentWebDAVItems = _webDAV.login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword(), _loginView->getIgnoreCert());; + std::vector currentWebDAVItems = _webDAV.login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword(), _loginView->getIgnoreCert()); if (currentWebDAVItems.empty()) { Message(ICON_ERROR, "Error", "Login failed.", 1000); diff --git a/src/handler/fileHandler.cpp b/src/handler/fileHandler.cpp index e3f385c..c9815e3 100644 --- a/src/handler/fileHandler.cpp +++ b/src/handler/fileHandler.cpp @@ -93,7 +93,6 @@ bool FileHandler::excludeFile(std::string filename) { if (_useRegex) { try { bool t = std::regex_match(filename, _regex) != _invertMatch; - string ta = t ? "true" : "false"; return t; } catch (std::regex_error err) { string errM = err.what();