diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2026-10-15 05:17:26 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska-skaware@skarnet.org> | 2026-10-15 05:17:26 +0000 |
| commit | 91a0655557e707977f583b2142bda898ee599fd8 (patch) | |
| tree | b5dd235420095136c99893bfb91618fed79a9918 /src/repo/s6rc_repo_setuptodate.c | |
| parent | 1feee8fff883b4e767a79e9373a96591d46eb8a2 (diff) | |
| download | s6-rc-91a0655557e707977f583b2142bda898ee599fd8.tar.gz | |
Second part of the format-upgrade support: ensure snapshots are there
We don't want to install compiled dbs without having a snapshot of
their source set, so whenever we test that the compiled db is up to
date, we also test that a snapshot is present. This is important
because we will auto-cleanup unused snapshots after installation.
Diffstat (limited to 'src/repo/s6rc_repo_setuptodate.c')
| -rw-r--r-- | src/repo/s6rc_repo_setuptodate.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/repo/s6rc_repo_setuptodate.c b/src/repo/s6rc_repo_setuptodate.c index f01143f..cfc6731 100644 --- a/src/repo/s6rc_repo_setuptodate.c +++ b/src/repo/s6rc_repo_setuptodate.c @@ -6,6 +6,7 @@ #include <string.h> #include <stdint.h> #include <errno.h> +#include <unistd.h> #include <skalibs/stat.h> #include <skalibs/strerr.h> @@ -34,12 +35,43 @@ int s6rc_repo_setuptodate (char const *repo, char const *set) strerr_warnfusys("stat ", srcfn) ; return -1 ; } + + /* Do we have a compiled db for this set? */ if (stat(dstfn, &stcompiled) == -1) { if (errno == ENOENT) return 0 ; strerr_warnfusys("stat ", dstfn) ; return -1 ; } + + /* Do we have a snapshot of the source set for the compiled db? */ + { + struct stat stsnap ; + char snap[repolen + 54 + setlen] ; + ssize_t r ; + memcpy(snap, srcfn, repolen + 9) ; + memcpy(snap + repolen + 9, ".snapshot", 9) ; + r = readlink(dstfn, snap + repolen + 18, setlen + 35) ; + if (r == -1) + { + strerr_warnfusys("readlink ", dstfn) ; + return -1 ; + } + if (r != setlen + 34) + { + strerr_warnf("invalid symlink: ", dstfn) ; + return -1 ; + } + snap[repolen + setlen + 53] = 0 ; + if (stat(snap, &stsnap) == -1) + { + if (errno == ENOENT) return 0 ; + strerr_warnfusys("stat ", snap) ; + return -1 ; + } + } + + /* Has the compiled db been built with the latest major s6-rc version? */ { uint32_t version = s6rc_repo_read_major(dstfn) ; if (!version) @@ -49,6 +81,8 @@ int s6rc_repo_setuptodate (char const *repo, char const *set) } if (version < s6rc_get_major(S6RC_VERSION)) return 0 ; } + + /* Is the compiled db more recent than the source set? */ return stsource.st_mtim.tv_sec < stcompiled.st_mtim.tv_sec ? 1 : stsource.st_mtim.tv_sec > stcompiled.st_mtim.tv_sec ? 0 : |
