From 7c93a058c8d7e21aea2aad8f3114c8422bf6faf7 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 2 Oct 2026 02:22:28 +0000 Subject: 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. --- src/repo/s6rc_repo_setcopy.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/repo/s6rc_repo_setcopy.c (limited to 'src/repo/s6rc_repo_setcopy.c') diff --git a/src/repo/s6rc_repo_setcopy.c b/src/repo/s6rc_repo_setcopy.c new file mode 100644 index 0000000..30cb042 --- /dev/null +++ b/src/repo/s6rc_repo_setcopy.c @@ -0,0 +1,66 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include + +#include + +static void cleanup (char const *s) +{ + int e = errno ; + rm_rf(s) ; + errno = e ; +} + +int s6rc_repo_setcopy (char const *repo, char const *srcname, char const *dstname, unsigned int 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) return errno ; + } + else if (!(flags & 1)) return -1 ; + + memcpy(realsrc, src, repolen + 9) ; + r = readlink(src, realsrc + repolen + 9, srclen + 9) ; + if (r == -1) return errno ; + if (r != srclen + 8) return -2 ; + 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) return errno ; + if (!hiercopy(realsrc, realdst)) + { + cleanup(realdst) ; + return errno ; + } + if (!atomic_symlink4(realdst + repolen + 9, dst, olddst + repolen + 9, dstlen + 9)) + { + cleanup(realdst) ; + return errno ; + } + if (olddst[repolen + 9]) cleanup(olddst) ; + return 0 ; +} -- cgit v1.3.1