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