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

use new resolve file format

parent cdc9615f
No related branches found
No related tags found
No related merge requests found
......@@ -21,21 +21,23 @@
#include <skalibs/stralloc.h>
#include <66/environ.h>
#include <66/service.h>
#include <66/parser.h>
int env_compute(stralloc *result,sv_alltype *sv, uint8_t conf)
int env_compute(stralloc *result, resolve_service_t *res)
{
log_flow() ;
int r ;
char *version = keep.s + sv->cname.version ;
char *svconf = keep.s + sv->srconf ;
char *name = keep.s + sv->cname.name ;
uint32_t conf = res->environ.env_overwrite ;
char *version = res->sa.s + res->version ;
char *svconf = res->sa.s + res->environ.envdir ;
char *name = res->sa.s + res->name ;
size_t svconf_len = strlen(svconf), version_len = strlen(version) ;
char src[svconf_len + 1 + version_len + 1] ;
auto_strings(src,svconf,"/",version) ;
auto_strings(src, svconf, "/", version) ;
/** previous version, this is the current version before
* the switch with env_make_symlink() */
......@@ -45,40 +47,40 @@ int env_compute(stralloc *result,sv_alltype *sv, uint8_t conf)
/** store current configure file version before the switch
* of the symlink with the env_make_symlink() function */
r = env_find_current_version(&pversion,svconf) ;
r = env_find_current_version(&pversion, svconf) ;
if (r == -1)
log_warnu_return(LOG_EXIT_ZERO,"find previous configuration file version") ;
log_warnu_return(LOG_EXIT_ZERO, "find previous configuration file version") ;
if(!env_make_symlink(sv))
if(!env_make_symlink(res))
return 0 ;
/** !r means that previous version doesn't exist, no need to import anything */
if (r && !conf) {
r = env_find_current_version(&fversion,svconf) ;
r = env_find_current_version(&fversion, svconf) ;
/** should never happen, the env_make_symlink() die in case of error */
if (r <= 0)
log_warnu_return(LOG_EXIT_ZERO,"find current configuration file version") ;
log_warnu_return(LOG_EXIT_ZERO, "find current configuration file version") ;
char pv[pversion.len + 1] ;
char fv[fversion.len + 1] ;
if (!ob_basename(pv,pversion.s))
log_warnu_return(LOG_EXIT_ZERO,"get basename of: ",pversion.s) ;
if (!ob_basename(pv, pversion.s))
log_warnu_return(LOG_EXIT_ZERO, "get basename of: ", pversion.s) ;
if (!ob_basename(fv,fversion.s))
log_warnu_return(LOG_EXIT_ZERO,"get basename of: ",fversion.s) ;
if (!ob_basename(fv, fversion.s))
log_warnu_return(LOG_EXIT_ZERO, "get basename of: ", fversion.s) ;
if (!env_import_version_file(name,svconf,pv,fv,sv->cname.itype))
if (!env_import_version_file(name, svconf, pv, fv, res->type))
return 0 ;
}
if (!auto_stra(result, \
"## [STARTWARN]\n## DO NOT MODIFY THIS FILE, IT OVERWRITTEN AT UPGRADE TIME.\n## Uses \'66-env ", \
name,"\' command instead.\n## Or make a copy of this file at ",src,"/",name, \
" and modify it.\n## [ENDWARN]\n",sv->saenv.s))
name,"\' command instead.\n## Or make a copy of this file at ", src, "/", name, \
" and modify it.\n## [ENDWARN]\n", res->sa.s + res->environ.env))
log_warnu_return(LOG_EXIT_ZERO,"stralloc") ;
stralloc_free(&pversion) ;
......
......@@ -23,14 +23,15 @@
#include <66/environ.h>
#include <66/parser.h>
#include <66/constants.h>
#include <66/service.h>
int env_make_symlink(sv_alltype *sv)
int env_make_symlink(resolve_service_t *res)
{
log_flow() ;
/** svconf-> /etc/66/conf/<service_name> */
char *svconf = keep.s + sv->srconf ;
char *version = keep.s + sv->cname.version ;
char *svconf = res->sa.s + res->environ.envdir ;
char *version = res->sa.s + res->version ;
size_t version_len = strlen(version), svconf_len = strlen(svconf) ;
char sym_version[svconf_len + SS_SYM_VERSION_LEN + 1] ;
......
......@@ -23,30 +23,27 @@
#include <66/environ.h>
#include <66/constants.h>
#include <66/service.h>
#include <66/parser.h>
int env_prepare_for_write(stralloc *name, stralloc *dst, stralloc *contents, sv_alltype *sv,uint8_t conf)
int env_prepare_for_write(stralloc *dst, stralloc *contents, resolve_service_t *res)
{
log_flow() ;
char *svconf = keep.s + sv->srconf ;
size_t svconf_len = strlen(svconf) ;
char sym[svconf_len + SS_SYM_VERSION_LEN + 1] ;
char *conf = res->sa.s + res->environ.envdir ;
size_t conflen = strlen(conf) ;
char sym[conflen + SS_SYM_VERSION_LEN + 1] ;
auto_strings(sym,svconf,SS_SYM_VERSION) ;
auto_strings(sym, conf, SS_SYM_VERSION) ;
if (!env_compute(contents,sv,conf))
log_warnu_return(LOG_EXIT_ZERO,"compute environment") ;
if (!env_compute(contents, res))
log_warnu_return(LOG_EXIT_ZERO, "compute environment") ;
if (sareadlink(dst, sym) == -1)
log_warnusys_return(LOG_EXIT_ZERO,"read link of: ",sym) ;
log_warnusys_return(LOG_EXIT_ZERO, "read link of: ", sym) ;
if (!stralloc_0(dst))
log_warnusys_return(LOG_EXIT_ZERO,"stralloc") ;
if (!auto_stra(name,".",keep.s + sv->cname.name))
log_warnusys_return(LOG_EXIT_ZERO,"stralloc") ;
log_warnusys_return(LOG_EXIT_ZERO, "stralloc") ;
return 1 ;
}
......@@ -13,7 +13,6 @@
*/
#include <sys/types.h>
#include <string.h>
#include <oblibs/log.h>
#include <oblibs/string.h>
......
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