aboutsummaryrefslogtreecommitdiffstats
path: root/src/repo/s6rc_repo_setdelete.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/s6rc_repo_setdelete.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/s6rc_repo_setdelete.c')
-rw-r--r--src/repo/s6rc_repo_setdelete.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/repo/s6rc_repo_setdelete.c b/src/repo/s6rc_repo_setdelete.c
new file mode 100644
index 0000000..a372d93
--- /dev/null
+++ b/src/repo/s6rc_repo_setdelete.c
@@ -0,0 +1,30 @@
+/* ISC license. */
+
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <skalibs/posixplz.h>
+#include <skalibs/djbunix.h>
+
+#include <s6-rc/repo.h>
+
+void s6rc_repo_setdelete (char const *repo, char const *set)
+{
+ size_t repolen = strlen(repo) ;
+ size_t setlen = strlen(set) ;
+ ssize_t r ;
+ char real[repolen + setlen + 18] ;
+ char fn[repolen + setlen + 11] ;
+ memcpy(fn, repo, repolen) ;
+ memcpy(fn + repolen, "/sources/", 9) ;
+ memcpy(fn + repolen + 9, set, setlen + 1) ;
+ if (access(fn, W_OK) == -1 && errno != ENOENT) return ;
+ memcpy(real, repo, repolen) ;
+ memcpy(real + repolen, "/sources/", 9) ;
+ r = readlink(fn, real + repolen + 9, setlen + 9) ;
+ if (r == -1 || r != setlen + 8) return ;
+ real[repolen + setlen + 17] = 0 ;
+ unlink_void(fn) ;
+ rm_rf(real) ;
+}