diff options
author | Joursoir <chat@joursoir.net> | 2022-08-19 22:28:26 +0300 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2022-08-21 23:50:14 +0300 |
commit | 56d9586130f0a5157543f24f567444608819c19c (patch) | |
tree | cd5011b5098fb095ad1bf7e46aefb6a7547d7c52 | |
parent | 26d676725d062bde8778a36b567221a39e28bdd7 (diff) | |
download | lock-password-56d9586130f0a5157543f24f567444608819c19c.tar.gz lock-password-56d9586130f0a5157543f24f567444608819c19c.tar.bz2 lock-password-56d9586130f0a5157543f24f567444608819c19c.zip |
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.
-rw-r--r-- | src/lpass.c | 23 |
1 files 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); |