aboutsummaryrefslogtreecommitdiffstats
path: root/src/repo/s6-rc-set-copy.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2026-10-02 02:22:28 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2026-10-02 02:22:28 +0000
commit7c93a058c8d7e21aea2aad8f3114c8422bf6faf7 (patch)
treeae569edcc313796b679ec8374e50668c973ffd5f /src/repo/s6-rc-set-copy.c
parent3a151bcd1835e1f7871a93c5b0d90f856562a98a (diff)
downloads6-rc-7c93a058c8d7e21aea2aad8f3114c8422bf6faf7.tar.gz
First part of the format-upgrade support in repo
In order to work across major bumps, we need to add a call to s6-rc-format-upgrade before s6-rc-update in the s6-rc-set-install sequence of commands. s6-rc-format-upgrade only works when the db is exactly the same across s6-rc versions. That means we need to have the source version of the current live set at all times, in order to compile it with the new s6-rc version before upgrading and then updating. So: 1. we take a snapshot of the source version of a set every time we commit. 2. we refuse to install if we don't have the snapshot. 3. we add s6-rc-format-upgrade to the processing chain 4. for cleanup: after installing, we delete all the snapshots of the set except the one that corresponds to the newly installed live set. This commit implements 1: taking the snapshot. It's a regular s6-rc-set-copy, using an internal name. We refactor s6-rc-set-copy and s6-rc-set-delete to have primitives we can use internally. Wait for later commits before using repo, else you'll fill your repository with snapshots that won't get cleaned up. TBD: how to store the s6-rc version in the compiled db. We probably need to add a small file in there.
Diffstat (limited to 'src/repo/s6-rc-set-copy.c')
-rw-r--r--src/repo/s6-rc-set-copy.c67
1 files changed, 9 insertions, 58 deletions
diff --git a/src/repo/s6-rc-set-copy.c b/src/repo/s6-rc-set-copy.c
index 8cef993..13e14a5 100644
--- a/src/repo/s6-rc-set-copy.c
+++ b/src/repo/s6-rc-set-copy.c
@@ -2,14 +2,10 @@
#include <string.h>
#include <unistd.h>
-#include <errno.h>
#include <skalibs/uint64.h>
-#include <skalibs/posixplz.h>
#include <skalibs/envexec.h>
-#include <skalibs/tai.h>
#include <skalibs/djbunix.h>
-#include <skalibs/unix-transactional.h>
#include <s6-rc/config.h>
#include <s6-rc/s6rc.h>
@@ -40,68 +36,23 @@ static gol_arg const rgola[] =
{ .so = 'r', .lo = "repodir", .i = GOLA_REPODIR }
} ;
-
-static uint64_t wgolb = 0 ;
-
-static void cleanup (char const *fn)
-{
- int e = errno ;
- rm_rf(fn) ;
- errno = e ;
-}
-
-static inline void docopy (char const *repo, char const *srcname, char const *dstname)
+static inline void docopy (char const *repo, char const *srcname, char const *dstname, uint64_t flags)
{
- size_t repolen = strlen(repo) ;
- size_t srclen = strlen(srcname) ;
- size_t dstlen = strlen(dstname) ;
- size_t r ;
- char src[repolen + srclen + 10] ;
- char dst[repolen + dstlen + 10] ;
- char realsrc[repolen + srclen + 18] ;
- char realdst[repolen + dstlen + 18] ;
- char olddst[repolen + dstlen + 18] ;
- memcpy(src, repo, repolen) ;
- memcpy(src + repolen, "/sources/", 9) ;
- memcpy(src + repolen + 9, srcname, srclen + 1) ;
- memcpy(dst, src, repolen + 9) ;
- memcpy(dst + repolen + 9, dstname, dstlen + 1) ;
- memcpy(olddst, dst, repolen + 9) ;
- olddst[repolen + 9] = 0 ;
- if (access(dst, F_OK) == -1)
- {
- if (errno != ENOENT) strerr_diefu2sys(111, "access ", dst) ;
- }
- else if (!(wgolb & GOLB_FORCE))
- strerr_dief4x(1, "set ", dstname, " already exists in repository ", repo) ;
-
- memcpy(realsrc, src, repolen + 9) ;
- r = readlink(src, realsrc + repolen + 9, srclen + 9) ;
- if (r == -1) strerr_diefu2sys(111, "readlink ", src) ;
- if (r != srclen + 8) strerr_dief3x(102, "symlink ", src, "doesn't point to a valid name") ;
- realsrc[repolen + srclen + 17] = 0 ;
- memcpy(realdst, dst, repolen + 9) ;
- realdst[repolen + 9] = '.' ;
- memcpy(realdst + repolen + 10, dstname, dstlen) ;
- memcpy(realdst + repolen + 10 + dstlen, ":XXXXXX", 8) ;
- if (mkntemp(realdst) == -1) strerr_diefu2sys(111, "mkntemp ", realdst) ;
- if (!hiercopy(realsrc, realdst))
- {
- cleanup(realdst) ;
- strerr_diefu4sys(111, "copy ", realsrc, " to ", realdst) ;
- }
- if (!atomic_symlink4(realdst + repolen + 9, dst, olddst + repolen + 9, dstlen + 9))
+ int e = s6rc_repo_setcopy(repo, srcname, dstname, !!(flags & GOLB_FORCE)) ;
+ switch (e)
{
- cleanup(realdst) ;
- strerr_diefu4sys(111, "symlink ", realdst + repolen + 9, " to ", dst) ;
+ case -2 : strerr_dief(102, "internal layout error: symlink inside ", srcname, " doesn't point to a valid name") ;
+ case -1 : strerr_dief(1, "set ", dstname, " already exists in repository ", repo) ;
+ case 0 : break ;
+ default : strerr_diefusys(111, "copy set ", srcname, " to set ", dstname) ;
}
- if (olddst[repolen + 9]) cleanup(olddst) ;
}
int main (int argc, char const *const *argv)
{
int fdlock ;
unsigned int verbosity = 1 ;
+ uint64_t wgolb = 0 ;
char const *wgola[GOLA_N] = { 0 } ;
unsigned int golc ;
@@ -121,6 +72,6 @@ int main (int argc, char const *const *argv)
tain_now_g() ;
fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ;
if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ;
- docopy(wgola[GOLA_REPODIR], argv[0], argv[1]) ;
+ docopy(wgola[GOLA_REPODIR], argv[0], argv[1], wgolb) ;
_exit(0) ;
}