From a33130f664647cebbd83bfc63f775b630672fd3a Mon Sep 17 00:00:00 2001 From: Aleksi Salmela Date: Tue, 2 May 2017 22:56:32 +0300 Subject: [PATCH] Fix more bugs creating/opening project. --- backend.cpp | 2 +- backend.h | 2 +- cli.cpp | 23 +++++++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/backend.cpp b/backend.cpp index a7fdc86..c90a860 100644 --- a/backend.cpp +++ b/backend.cpp @@ -1648,7 +1648,7 @@ std::string Config::getTaskerData(std::string path, std::string *source) return ""; } -void Config::setTaskerData(std::string path, std::string source) +void Config::setTaskerData(std::string source, std::string path) { mConfig.addRepository(source, path); diff --git a/backend.h b/backend.h index 8750430..b1efa21 100644 --- a/backend.h +++ b/backend.h @@ -372,7 +372,7 @@ class Config//< TODO this object should be thread safe static std::string guessProjectDir(std::string currentWorkDir); static std::string getSourceDir(std::string taskerPath); static std::string getTaskerData(std::string path, std::string *source = NULL); - static void setTaskerData(std::string path, std::string source); + static void setTaskerData(std::string source, std::string path); private: Config(); ~Config(); diff --git a/cli.cpp b/cli.cpp index b474e73..5ae1d8f 100644 --- a/cli.cpp +++ b/cli.cpp @@ -27,7 +27,7 @@ #include #include -#ifdef _NO_READLINE_ +#ifndef _NO_READLINE_ # include # include #endif @@ -143,17 +143,27 @@ bool Main::init(int argc, char **argv) { char *cwd_tmp = get_current_dir_name(); std::string cwd = cwd_tmp; - std::string dir = Backend::Config::guessProjectDir(cwd); free(cwd_tmp); + std::string dir = Backend::Config::getTaskerData(cwd, NULL); + bool knownToExist = !dir.empty(); + if(!knownToExist) { + dir = cwd; + } + if(argc >= 2) { dir = argv[1]; + knownToExist = false; } mProject = Backend::Project::open(dir); if(mProject) { return true; } + if(knownToExist) { + std::cerr << "The config file contains non-existing project " << dir << "\n"; + return false; + } std::cerr << "Tasker data not found.\n"; while(true) { std::string prompt = "Create a new tasker repository? [y/n]"; @@ -164,12 +174,13 @@ bool Main::init(int argc, char **argv) return false; } } - mProject = Backend::Project::create("./"); dir = Main::getLine("Where do you want the issues?"); - char *buf = realpath(dir.c_str(), NULL); - dir.assign(buf); - free(buf); + // Ugly way to turn relative path to absolute path + if(dir[0] != '/') { + dir = cwd + "/" + dir; + } + mProject = Backend::Project::create(dir); Backend::Config::setTaskerData(cwd, dir); return true; }