diff --git a/src/include/66/backup.h b/src/include/66/backup.h deleted file mode 100644 index c44b0bd4ef634416bc2269a0572e648d3764de00..0000000000000000000000000000000000000000 --- a/src/include/66/backup.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * backup.h - * - * 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./ - */ - -#ifndef SS_BACKUP_H -#define SS_BACKUP_H - -#include <skalibs/stralloc.h> - -#include <66/ssexec.h> - -extern int backup_make_new(ssexec_t *info,unsigned int type) ; -extern int backup_cmd_switcher(unsigned int verbosity,char const *cmd, ssexec_t *info) ; -extern int backup_switcher(int argc, char const *const *argv,ssexec_t *info) ; -extern int backup_realpath_sym(stralloc *sa,ssexec_t *info,unsigned int type) ; - -#endif diff --git a/src/lib66/backup/backup_cmd_switcher.c b/src/lib66/backup/backup_cmd_switcher.c deleted file mode 100644 index e16c5f92ed08e1adc1c2a99fd550c6ed49d05015..0000000000000000000000000000000000000000 --- a/src/lib66/backup/backup_cmd_switcher.c +++ /dev/null @@ -1,195 +0,0 @@ -/* - * backup_cmd_switcher.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 <string.h> -#include <stdint.h> -#include <sys/stat.h> - -#include <oblibs/obgetopt.h> -#include <oblibs/log.h> -#include <oblibs/string.h> -#include <oblibs/sastr.h> - -#include <skalibs/stralloc.h> -#include <skalibs/types.h> -#include <skalibs/djbunix.h> -#include <skalibs/unix-transactional.h>//atomic_symlink - -#include <66/constants.h> -#include <66/enum.h> -#include <66/ssexec.h> - -//USAGE "backup_switcher [ -v verbosity ] [ -t type ] [ -b backup ] [ -s switch ] tree" -// for -b: return 0 if point to original source, return 1 if point to backup -// for -s: -s0 -> origin, -s1 -> backup ; -int backup_switcher(int argc, char const *const *argv,ssexec_t *info) -{ - unsigned int change, back, verbosity, type ; - uint32_t what = -1 ; - int r ; - struct stat st ; - - char const *tree = NULL ; - - verbosity = 1 ; - - change = back = 0 ; - type = -1 ; - - { - subgetopt l = SUBGETOPT_ZERO ; - - for (;;) - { - int opt = getopt_args(argc,argv, "v:t:s:b", &l) ; - if (opt == -1) break ; - if (opt == -2) log_warn_return(LOG_EXIT_LESSONE,"options must be set first") ; - switch (opt) - { - case 'v' : if (!uint0_scan(l.arg, &verbosity)) return -1 ; break ; - case 't' : if (!uint0_scan(l.arg, &type)) return -1 ; break ; - case 's' : change = 1 ; if (!uint0_scan(l.arg, &what)) return -1 ; break ; - case 'b' : back = 1 ; break ; - default : return -1 ; - } - } - argc -= l.ind ; argv += l.ind ; - } - - if (argc < 1) return -1 ; - if ((!change && !back) || type < 0) return -1 ; - - if (type < TYPE_CLASSIC || type > TYPE_ONESHOT) - log_warn_return(LOG_EXIT_LESSONE,"unknown type for backup_switcher") ; - - tree = *argv ; - size_t treelen = strlen(tree) ; - - /** $HOME/66/system/tree/servicedirs */ - //base.len-- ; - size_t psymlen ; - char *psym = NULL ; - if (type == TYPE_CLASSIC) { - psym = SS_SYM_SVC ; - psymlen = SS_SYM_SVC_LEN ; - - } else { - psym = SS_SYM_DB ; - psymlen = SS_SYM_DB_LEN ; - } - - char sym[info->base.len + SS_SYSTEM_LEN + 1 + treelen + SS_SVDIRS_LEN + 1 + psymlen + 1] ; - auto_strings(sym, info->base.s, SS_SYSTEM, "/", tree, SS_SVDIRS, "/", psym) ; - - if (back) { - - if(lstat(sym,&st) < 0) return -1 ; - if(!(S_ISLNK(st.st_mode))) - log_warnusys_return(LOG_EXIT_LESSONE,"find symlink: ",sym) ; - - stralloc symreal = STRALLOC_ZERO ; - - r = sarealpath(&symreal,sym) ; - if (r < 0) - log_warnusys_return(LOG_EXIT_LESSONE,"retrieve real path from: ",sym) ; - - char *b = NULL ; - b = memmem(symreal.s,symreal.len,SS_BACKUP,SS_BACKUP_LEN) ; - - stralloc_free(&symreal) ; - - if (!b) return SS_SWSRC ; - - return SS_SWBACK ; - } - - if (change) { - - size_t psrclen ; - size_t pbacklen ; - char *psrc = NULL ; - char *pback = NULL ; - - if (type == TYPE_CLASSIC) { - psrc = SS_SVC ; - psrclen = SS_SVC_LEN ; - - pback = SS_SVC ; - pbacklen = SS_SVC_LEN ; - - } else { - - psrc = SS_DB ; - psrclen = SS_DB_LEN ; - - pback = SS_DB ; - pbacklen = SS_DB_LEN ; - } - - char dstsrc[info->base.len + SS_SYSTEM_LEN + 1 + treelen + SS_SVDIRS_LEN + psrclen + 1] ; - char dstback[info->base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + treelen + pbacklen + 1] ; - - auto_strings(dstsrc, info->base.s, SS_SYSTEM, "/", tree, SS_SVDIRS, psrc) ; - - auto_strings(dstback, info->base.s, SS_SYSTEM, SS_BACKUP, "/", tree, pback) ; - - if (what) { - - if (!atomic_symlink(dstback, sym,"backup_switcher")) - log_warnusys_return(LOG_EXIT_LESSONE,"symlink: ", dstback) ; - } - - if (!what) { - - if (!atomic_symlink(dstsrc, sym,"backup_switcher")) - log_warnusys_return(LOG_EXIT_LESSONE,"symlink: ", dstsrc) ; - } - } - - return 1 ; -} - -int backup_cmd_switcher(unsigned int verbosity,char const *cmd,ssexec_t *info) -{ - log_flow() ; - - int r ; - size_t pos = 0 ; - stralloc opts = STRALLOC_ZERO ; - - if (!sastr_clean_string(&opts,cmd)) - log_warnu_return(LOG_EXIT_LESSONE,"clean: ",cmd) ; - - int newopts = 5 + sastr_len(&opts) ; - char const *newargv[newopts] ; - unsigned int m = 0 ; - char fmt[UINT_FMT] ; - fmt[uint_fmt(fmt, verbosity)] = 0 ; - - newargv[m++] = "backup_switcher" ; - newargv[m++] = "-v" ; - newargv[m++] = fmt ; - - FOREACH_SASTR(&opts, pos) - newargv[m++] = opts.s + pos ; - - newargv[m++] = info->treename.s ; - newargv[m++] = 0 ; - - r = backup_switcher(newopts,newargv,info) ; - - stralloc_free(&opts) ; - - return r ; -} diff --git a/src/lib66/backup/backup_make_new.c b/src/lib66/backup/backup_make_new.c deleted file mode 100644 index 20ece2fcda0f68e5c5f52514c0a06fb33825ea1b..0000000000000000000000000000000000000000 --- a/src/lib66/backup/backup_make_new.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * backup_make_new.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 <sys/stat.h> -#include <stddef.h> - -#include <oblibs/log.h> -#include <oblibs/types.h> -#include <oblibs/directory.h> -#include <oblibs/string.h> - -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> - -#include <66/constants.h> -#include <66/enum.h> -#include <66/resolve.h> -#include <66/tree.h> -#include <66/db.h> - -// force: 0->check, 1->remove and create -int backup_make_new(ssexec_t *info, unsigned int type) -{ - log_flow() ; - - int r ; - - size_t newsrc, newback ; - char *ptype = NULL ; - - if (type == TYPE_CLASSIC) { - - ptype = SS_SVC ; - - } else { - - ptype = SS_DB ; - - } - - char src[info->base.len + SS_SYSTEM_LEN + 1 + info->treename.len + SS_SVDIRS_LEN + SS_RESOLVE_LEN + 1] ; - auto_strings(src, info->base.s, SS_SYSTEM, "/", info->treename.s, SS_SVDIRS, ptype) ; - newsrc = info->base.len + SS_SYSTEM_LEN + 1 + info->treename.len + SS_SVDIRS_LEN ; - - char back[info->base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + info->treename.len + SS_RESOLVE_LEN + 1] ; - auto_strings(back, info->base.s, SS_SYSTEM, SS_BACKUP, "/", info->treename.s, ptype) ; - newback = info->base.len + SS_SYSTEM_LEN + SS_BACKUP_LEN + 1 + info->treename.len ; - - r = scan_mode(back,S_IFDIR) ; - if (r || (r < 0)) { - - log_trace("rm directory: ", back) ; - if (rm_rf(back) < 0) - log_warnusys_return(LOG_EXIT_ZERO,"remove: ",back) ; - - r = 0 ; - } - - if (!r) { - - log_trace("create directory: ", back) ; - if (!dir_create(back,0755)) - log_warnusys_return(LOG_EXIT_ZERO,"create directory: ",back) ; - } - - log_trace("copy: ",src," to: ", back) ; - if (!hiercopy(src, back)) - log_warnusys_return(LOG_EXIT_ZERO,"copy: ",src," to ",back) ; - - memcpy(src + newsrc,SS_RESOLVE,SS_RESOLVE_LEN) ; - src[newsrc + SS_RESOLVE_LEN] = 0 ; - - memcpy(back + newback,SS_RESOLVE,SS_RESOLVE_LEN) ; - back[newback + SS_RESOLVE_LEN] = 0 ; - - r = scan_mode(back,S_IFDIR) ; - if (r || (r < 0)) { - - log_trace("rm directory: ", back) ; - if (rm_rf(back) < 0) - log_warnusys_return(LOG_EXIT_ZERO,"remove: ",back) ; - - r = 0 ; - } - - if (!r) { - - log_trace("create directory: ", back) ; - if (!dir_create(back,0755)) - log_warnusys_return(LOG_EXIT_ZERO,"create directory: ",back) ; - } - - log_trace("copy: ",src," to: ", back) ; - if (!hiercopy(src, back)) - log_warnusys_return(LOG_EXIT_ZERO,"copy: ",src," to ",back) ; - - return 1 ; -} diff --git a/src/lib66/backup/backup_realpath_sym.c b/src/lib66/backup/backup_realpath_sym.c deleted file mode 100644 index 65bcce43099123cb7c6a31ff26e23d6a2f899422..0000000000000000000000000000000000000000 --- a/src/lib66/backup/backup_realpath_sym.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * backup_realpath_sym.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/utils.h> - -#include <sys/types.h> -#include <string.h> - -#include <oblibs/log.h> -#include <oblibs/types.h> -#include <oblibs/string.h> - -#include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> - -#include <66/constants.h> -#include <66/enum.h> -#include <66/ssexec.h> - -int backup_realpath_sym(stralloc *sa, ssexec_t *info,unsigned int type) -{ - log_flow() ; - - ssize_t r ; - size_t typelen ; - char *ptype = 0 ; - - if (type == TYPE_CLASSIC) { - ptype = SS_SYM_SVC ; - typelen = SS_SYM_SVC_LEN; - - } else { - - ptype = SS_SYM_DB ; - typelen = SS_SYM_DB_LEN; - } - - char sym[info->tree.len + SS_SVDIRS_LEN + 1 + typelen + 1] ; - auto_strings(sym, info->tree.s, SS_SVDIRS, "/", ptype, "/") ; - - r = scan_mode(sym,S_IFDIR) ; - if(r <= 0) - return 0 ; - - sa->len = 0 ; - r = sarealpath(sa,sym) ; - if (r == -1 ) - return 0 ; - - if (!stralloc_0(sa)) - log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ; - - return 1 ; -} diff --git a/src/lib66/backup/deps-lib/deps b/src/lib66/backup/deps-lib/deps index 4254f896428c2643235321b47ccf9d1cad51e80f..aa08a1493330806f8a201d878aa14bb087db05a3 100644 --- a/src/lib66/backup/deps-lib/deps +++ b/src/lib66/backup/deps-lib/deps @@ -1,6 +1,3 @@ -backup_cmd_switcher.o -backup_make_new.o -backup_realpath_sym.o -loblibs -lskarnet diff --git a/src/lib66/state/template.c b/src/lib66/state/template.c deleted file mode 100644 index b1130bedb7862441667de227469e8332bc7bc4e5..0000000000000000000000000000000000000000 --- a/src/lib66/state/template.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * service.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/state.h>