Skip to content
Snippets Groups Projects
Commit 0b239cf8 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

Provide a current tree by default. End of use of tree path

parent 9f097519
No related branches found
No related tags found
No related merge requests found
......@@ -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 ;
......
/*
* 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 ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment