From 56d9586130f0a5157543f24f567444608819c19c Mon Sep 17 00:00:00 2001 From: Joursoir Date: Fri, 19 Aug 2022 22:28:26 +0300 Subject: lpass: create root directory only if it doesn't exist. No need to try to create a directory in other cases, because that won't help. --- src/lpass.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/lpass.c b/src/lpass.c index f2281e2..2fcc1ad 100644 --- a/src/lpass.c +++ b/src/lpass.c @@ -61,18 +61,23 @@ static struct cmd_struct *get_cmd(const char *name) static int goto_maindir() { - int retval = 0, result; + int result; char *rootdir = xstrcat(getenv("HOME"), LOCKPASS_DIR, "/"); - if(chdir(rootdir)) // failed + int retval = chdir(rootdir); + if(retval) // failed { - // create main directory: - result = mkdir(rootdir, S_IRWXU); - if(result) { - if(errno != EEXIST) - print_error("Error: %s\n", strerror(errno)); + if(errno == ENOENT) { + // create main directory: + result = mkdir(rootdir, S_IRWXU); + if(result) { + if(errno != EEXIST) + print_error("Error: %s\n", strerror(errno)); + } + else // try again: + retval = chdir(rootdir); + } else { + print_error("Error: %s\n", strerror(errno)); } - else // try again: - retval = chdir(rootdir); } free(rootdir); -- cgit v1.2.3-18-g5258