diff --git a/src/lib66/tree/tree_sethome.c b/src/lib66/tree/tree_sethome.c index 6f071ce96cddfc97c954d26ab805fc79f712a13e..f453e3294bd7a8c6e320d3e38bed4d5fb7abc520 100644 --- a/src/lib66/tree/tree_sethome.c +++ b/src/lib66/tree/tree_sethome.c @@ -18,15 +18,14 @@ #include <oblibs/log.h> #include <oblibs/string.h> +#include <66/config.h> #include <66/constants.h> #include <66/ssexec.h> #include <66/tree.h> /** - * @Return -3 > unable to find current - * @Return -2 > unable to fix tree name - * @Return -1 > unable to parse seed file - * @Return 0 > tree doesn't exist + * @Return -1 > error system + * @Return 0 > unable to find seed file * @Return 1 > success */ int tree_sethome(ssexec_t *info) { @@ -38,15 +37,22 @@ int tree_sethome(ssexec_t *info) if (!info->opt_tree) { - if (!tree_find_current(&info->tree, base)) { - /** no current tree found. Use the default one. */ - info->tree.len = 0 ; - if (!auto_stra(&info->tree, base, SS_SYSTEM, "/", SS_DEFAULT_TREENAME)) - return 0 ; - } + char t[SS_MAX_TREENAME + 1] ; + r = tree_find_current(t, base) ; + + if (r < 0) + return -1 ; + info->treename.len = 0 ; - if (!tree_setname(&info->treename, info->tree.s)) - return -2 ; + if (!r) { + /** no current tree found. Use the default one.*/ + if (!auto_stra(&info->treename, SS_DEFAULT_TREENAME)) + return -1 ; + } else { + + if (!auto_stra(&info->treename, t)) + return -1 ; + } } else { @@ -56,7 +62,7 @@ int tree_sethome(ssexec_t *info) /** The tree name exist on the system * but it's not a directory */ errno = EEXIST ; - return 0 ; + return -1 ; } else if (!r) { @@ -77,16 +83,10 @@ int tree_sethome(ssexec_t *info) char const *prog = PROG ; PROG = "tree" ; if (ssexec_tree_admin(nargc, newargv, info)) - log_warnu_return(LOG_EXIT_ZERO,"create tree: ",info->treename.s) ; + log_warnu_return(LOG_EXIT_LESSONE,"create tree: ",info->treename.s) ; PROG = prog ; } - /** The tree_sethome() function can be recursively called. The info->tree may not be empty. - * Be sure to clean up before using it. */ - info->tree.len = 0 ; - if (!auto_stra(&info->tree, base, SS_SYSTEM, "/", info->treename.s)) - log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; - } return 1 ; diff --git a/src/lib66/tree/tree_setname.c b/src/lib66/tree/tree_setname.c deleted file mode 100644 index e4bfcf23efeacfa424d92f3c927c699dec4603ea..0000000000000000000000000000000000000000 --- a/src/lib66/tree/tree_setname.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * tree_setname.c - * - * Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org> - * - * All rights reserved. - * - * This file is part of Obarun. It is subject to the license terms in - * the LICENSE file found in the top-level directory of this - * distribution. - * This file may not be copied, modified, propagated, or distributed - * except according to the terms contained in the LICENSE file./ - */ - -#include <66/tree.h> - -#include <string.h> -#include <sys/types.h>//ssize - -#include <oblibs/string.h> -#include <oblibs/log.h> - -#include <skalibs/stralloc.h> - -char tree_setname(stralloc *sa,char const *tree) -{ - log_flow() ; - - size_t tlen = strlen(tree) ; - ssize_t treelen = get_rlen_until(tree,'/',tlen) ; - if (treelen <= 0) return 0 ; - treelen++ ; - size_t treenamelen = tlen - treelen ; - - if (!stralloc_catb(sa,tree + treelen,treenamelen)) return 0 ; - if (!stralloc_0(sa)) return 0 ; - sa->len--; - return 1 ; -}