aboutsummaryrefslogtreecommitdiffstats
path: root/src/repo
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-10-01 01:02:29 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2025-10-01 01:02:29 +0000
commit8effedb35bb873a1278776721a0d650c665efaa7 (patch)
tree6833ace13f8c5eee4254fdd41cb6391a01394c98 /src/repo
parent04186b51dfcada174b5372aab0c7e423a4ed3244 (diff)
downloads6-rc-8effedb35bb873a1278776721a0d650c665efaa7.tar.gz
Add stores, edit init and sync
Diffstat (limited to 'src/repo')
-rw-r--r--src/repo/s6-rc-repo-init.c177
-rw-r--r--src/repo/s6-rc-repo-sync.c8
-rw-r--r--src/repo/s6-rc-set-changestate.c2
-rw-r--r--src/repo/s6-rc-set-commit.c4
-rw-r--r--src/repo/s6-rc-set-copy.c2
-rw-r--r--src/repo/s6-rc-set-delete.c2
-rw-r--r--src/repo/s6-rc-set-new.c2
7 files changed, 96 insertions, 101 deletions
diff --git a/src/repo/s6-rc-repo-init.c b/src/repo/s6-rc-repo-init.c
index 8c65203..b105200 100644
--- a/src/repo/s6-rc-repo-init.c
+++ b/src/repo/s6-rc-repo-init.c
@@ -4,6 +4,7 @@
#include <skalibs/nonposix.h> /* mkdtemp */
#include <string.h>
+#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h> /* rename */
@@ -13,7 +14,6 @@
#include <skalibs/stat.h>
#include <skalibs/posixplz.h>
#include <skalibs/gol.h>
-#include <skalibs/tai.h>
#include <skalibs/prog.h>
#include <skalibs/strerr.h>
#include <skalibs/djbunix.h>
@@ -22,7 +22,7 @@
#include <s6-rc/config.h>
#include <s6-rc/s6rc.h>
-#define USAGE "s6-rc-repo-init [ -v verbosity ] [ -r repo ] [ -h fdhuser ] [ -B ] [ -f ] stores..."
+#define USAGE "s6-rc-repo-init [ -v verbosity ] [ -r repo ] [ -h fdhuser ] [ -f ] [ -U ] [ -B ] stores..."
#define dieusage() strerr_dieusage(100, USAGE)
static void cleanup (char const *fn)
@@ -35,13 +35,15 @@ static void cleanup (char const *fn)
enum golb_e
{
GOLB_FORCE = 0x01,
- GOLB_BARE = 0x02
+ GOLB_UPDATE = 0x02,
+ GOLB_BARE = 0x04
} ;
static gol_bool const rgolb[] =
{
{ .so = 'f', .lo = "force", .clear = 0, .set = GOLB_FORCE },
- { .so = 'S', .lo = "bare", .clear = 0, .set = GOLB_BARE }
+ { .so = 'U', .lo = "update-stores", .clear = 0, .set = GOLB_UPDATE },
+ { .so = 'B', .lo = "bare", .clear = 0, .set = GOLB_BARE }
} ;
enum gola_e
@@ -56,17 +58,17 @@ static gol_arg const rgola[] =
{
{ .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY },
{ .so = 'r', .lo = "repodir", .i = GOLA_REPODIR },
- { .so = 'h', .lo = "fd-holder-user", .i = GOLA_FDHUSER }
+ { .so = 'h', .lo = "fdholder-user", .i = GOLA_FDHUSER }
} ;
int main (int argc, char const *const *argv)
{
- size_t repolen ;
unsigned int verbosity = 1 ;
- mode_t m ;
char const *wgola[GOLA_N] = { 0 } ;
uint64_t wgolb = 0 ;
unsigned int golc ;
+ size_t repolen ;
+ int lockfd ;
PROG = "s6-rc-repo-init" ;
wgola[GOLA_REPODIR] = S6RC_REPO_BASE ;
@@ -74,116 +76,117 @@ int main (int argc, char const *const *argv)
golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ;
argc -= golc ; argv += golc ;
if (!argc) dieusage() ;
+ if (argc > UINT16_MAX) strerr_dief1x(100, "too many stores specified") ;
if (wgola[GOLA_VERBOSITY] && !uint0_scan(wgola[GOLA_VERBOSITY], &verbosity))
strerr_dief1x(100, "verbosity needs to be an unsigned integer") ;
- for (unsigned int i = 0 ; i < argc ; i++)
+ for (uint16_t i = 0 ; i < argc ; i++)
{
if (argv[i][0] != '/')
strerr_dief2x(100, argv[i], " is not an absolute path") ;
if (strchr(argv[i], '\n'))
strerr_dief1x(100, "stores cannot contain newlines in their path") ;
}
- tain_now_g() ;
repolen = strlen(wgola[GOLA_REPODIR]) ;
- char repotmp[repolen + 12] ;
- char tmp[repolen + 29] ;
- memcpy(repotmp, wgola[GOLA_REPODIR], repolen) ;
- memcpy(repotmp + repolen, ":new:XXXXXX", 12) ;
- m = umask(0) ;
- if (!mkdtemp(repotmp))
+
+ if (!(wgolb & GOLB_UPDATE))
{
- size_t i = repolen ;
- if (errno != ENOENT)
- strerr_diefu2sys(111, "mkdtemp ", repotmp) ;
- while (i && repotmp[i] != '/') i-- ;
- repotmp[i] = 0 ;
- if (mkdirp2(repotmp, 02755) == -1)
- strerr_diefu2sys(111, "mkdir ", repotmp) ;
- repotmp[i] = '/' ;
+ mode_t m ;
+ char repotmp[repolen + 12] ;
+ char tmp[repolen + 29] ;
+ memcpy(repotmp, wgola[GOLA_REPODIR], repolen) ;
memcpy(repotmp + repolen, ":new:XXXXXX", 12) ;
+ m = umask(0) ;
if (!mkdtemp(repotmp))
- strerr_diefu2sys(111, "mkdtemp ", repotmp) ;
- }
- memcpy(tmp, repotmp, repolen + 11) ;
- tmp[repolen + 11] = '/' ;
-
- memcpy(tmp + repolen + 12, "compiled", 9) ;
- if (mkdir(tmp, 02755) == -1)
- {
- cleanup(repotmp) ;
- strerr_diefu2sys(111, "mkdir ", tmp) ;
- }
-
- memcpy(tmp + repolen + 12, "sources", 8) ;
- if (mkdir(tmp, 02755) == -1)
- {
- cleanup(repotmp) ;
- strerr_diefu2sys(111, "mkdir ", tmp) ;
- }
+ {
+ size_t i = repolen ;
+ if (errno != ENOENT)
+ strerr_diefu2sys(111, "mkdtemp ", repotmp) ;
+ while (i && repotmp[i] != '/') i-- ;
+ repotmp[i] = 0 ;
+ if (mkdirp2(repotmp, 02755) == -1)
+ strerr_diefu2sys(111, "mkdir ", repotmp) ;
+ repotmp[i] = '/' ;
+ memcpy(repotmp + repolen, ":new:XXXXXX", 12) ;
+ if (!mkdtemp(repotmp))
+ strerr_diefu2sys(111, "mkdtemp ", repotmp) ;
+ }
+ memcpy(tmp, repotmp, repolen + 11) ;
+ tmp[repolen + 11] = '/' ;
- memcpy(tmp + repolen + 12, "stores", 7) ;
- if (mkdir(tmp, 02755) == -1)
- {
- cleanup(repotmp) ;
- strerr_diefu2sys(111, "mkdir ", tmp) ;
- }
- umask(m) ;
- tmp[repolen + 19] = '/' ;
- for (unsigned int i = 0 ; i < argc ; i++)
- {
- uint320_xfmt(tmp + repolen + 20, i, 8) ;
- tmp[repolen + 28] = 0 ;
- if (symlink(argv[i], tmp) == -1)
+ memcpy(tmp + repolen + 12, "compiled", 9) ;
+ if (mkdir(tmp, 02755) == -1)
{
cleanup(repotmp) ;
- strerr_diefu4sys(111, "make a symlink from ", tmp, " to ", argv[i]) ;
+ strerr_diefu2sys(111, "mkdir ", tmp) ;
}
- }
- memcpy(tmp + repolen + 12, "lock", 5) ;
- if (!openwritenclose_unsafe5(tmp, "", 0, 0, 0))
- {
- cleanup(repotmp) ;
- strerr_diefu2sys(111, "create ", tmp) ;
- }
+ memcpy(tmp + repolen + 12, "sources", 8) ;
+ if (mkdir(tmp, 02755) == -1)
+ {
+ cleanup(repotmp) ;
+ strerr_diefu2sys(111, "mkdir ", tmp) ;
+ }
- if (!(wgolb & GOLB_BARE) && !s6rc_repo_sync(repotmp, verbosity, wgola[GOLA_FDHUSER]))
- {
- cleanup(repotmp) ;
- _exit(111) ;
- }
+ memcpy(tmp + repolen + 12, "stores", 7) ;
+ if (mkdir(tmp, 02755) == -1)
+ {
+ cleanup(repotmp) ;
+ strerr_diefu2sys(111, "mkdir ", tmp) ;
+ }
+ umask(m) ;
- if (chmod(repotmp, 02755) == -1)
- strerr_diefu2sys(111, "chmod ", repotmp) ;
- if (rename(repotmp, wgola[GOLA_REPODIR]) == -1)
- {
- if (errno != EEXIST || !(wgolb & GOLB_FORCE))
+ memcpy(tmp + repolen + 12, "lock", 5) ;
+ if (!openwritenclose_unsafe5(tmp, "", 0, 0, 0))
{
cleanup(repotmp) ;
- strerr_diefu4sys(111, "rename ", repotmp, " to ", wgola[GOLA_REPODIR]) ;
+ strerr_diefu2sys(111, "create ", tmp) ;
}
- else
+
+ if (chmod(repotmp, 02755) == -1)
+ strerr_diefu2sys(111, "chmod ", repotmp) ;
+
+ if (rename(repotmp, wgola[GOLA_REPODIR]) == -1)
{
- memcpy(tmp, wgola[GOLA_REPODIR], repolen) ;
- memcpy(tmp + repolen, ":old:", 5) ;
- random_name(tmp + repolen + 5, 15) ;
- tmp[repolen + 20] = 0 ;
- if (rename(wgola[GOLA_REPODIR], tmp) == -1)
+ if (errno != EEXIST || !(wgolb & GOLB_FORCE))
{
cleanup(repotmp) ;
- strerr_diefu4sys(111, "rename ", wgola[GOLA_REPODIR], " to ", tmp) ;
+ strerr_diefu4sys(111, "rename ", repotmp, " to ", wgola[GOLA_REPODIR]) ;
}
- if (rename(repotmp, wgola[GOLA_REPODIR]) == -1)
+ else
{
- int e = errno ;
- if (rename(tmp, wgola[GOLA_REPODIR]) == -1)
- strerr_diefu7sys(111, "rename directories to ", wgola[GOLA_REPODIR], ": weird race happened. New repository is at ", repotmp, " and old repository is at ", tmp, " - reported error was") ;
- errno = e ;
- cleanup(repotmp) ;
- strerr_diefu4sys(111, "rename ", repotmp, " to ", wgola[GOLA_REPODIR]) ;
+ memcpy(tmp, wgola[GOLA_REPODIR], repolen) ;
+ memcpy(tmp + repolen, ":old:", 5) ;
+ random_name(tmp + repolen + 5, 15) ;
+ tmp[repolen + 20] = 0 ;
+ if (rename(wgola[GOLA_REPODIR], tmp) == -1)
+ {
+ cleanup(repotmp) ;
+ strerr_diefu4sys(111, "rename ", wgola[GOLA_REPODIR], " to ", tmp) ;
+ }
+ if (rename(repotmp, wgola[GOLA_REPODIR]) == -1)
+ {
+ int e = errno ;
+ if (rename(tmp, wgola[GOLA_REPODIR]) == -1)
+ strerr_diefu7sys(111, "rename directories to ", wgola[GOLA_REPODIR], ": weird race happened. New repository is at ", repotmp, " and old repository is at ", tmp, " - reported error was") ;
+ errno = e ;
+ cleanup(repotmp) ;
+ strerr_diefu4sys(111, "rename ", repotmp, " to ", wgola[GOLA_REPODIR]) ;
+ }
}
}
}
+ lockfd = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ;
+ if (lockfd == -1)
+ strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ;
+
+ if (!s6rc_repo_makestores(wgola[GOLA_REPODIR], argv, argc)) _exit(111) ;
+
+ if (!(wgolb & GOLB_BARE))
+ {
+ if (!s6rc_repo_sync(wgola[GOLA_REPODIR], verbosity, wgola[GOLA_FDHUSER]))
+ _exit(111) ;
+ }
+
_exit(0) ;
}
diff --git a/src/repo/s6-rc-repo-sync.c b/src/repo/s6-rc-repo-sync.c
index f3768f7..751037c 100644
--- a/src/repo/s6-rc-repo-sync.c
+++ b/src/repo/s6-rc-repo-sync.c
@@ -3,7 +3,6 @@
#include <unistd.h>
#include <skalibs/gol.h>
-#include <skalibs/tai.h>
#include <skalibs/prog.h>
#include <skalibs/strerr.h>
@@ -25,7 +24,7 @@ static gol_arg const rgola[] =
{
{ .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY },
{ .so = 'r', .lo = "repodir", .i = GOLA_REPODIR },
- { .so = 'h', .lo = "fd-holder-user", .i = GOLA_FDHUSER }
+ { .so = 'h', .lo = "fdholder-user", .i = GOLA_FDHUSER }
} ;
int main (int argc, char const *const *argv)
@@ -33,6 +32,7 @@ int main (int argc, char const *const *argv)
char const *wgola[GOLA_N] = { 0 } ;
unsigned int verbosity = 1 ;
unsigned int golc ;
+ int fdlock ;
PROG = "s6-rc-repo-sync" ;
wgola[GOLA_REPODIR] = S6RC_REPO_BASE ;
@@ -41,7 +41,9 @@ int main (int argc, char const *const *argv)
argc -= golc ; argv += golc ;
if (wgola[GOLA_VERBOSITY] && !uint0_scan(wgola[GOLA_VERBOSITY], &verbosity))
strerr_dief1x(100, "verbosity needs to be an unsigned integer") ;
- tain_now_g() ;
+
+ fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ;
+ if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ;
if (!s6rc_repo_sync(wgola[GOLA_REPODIR], verbosity, wgola[GOLA_FDHUSER])) _exit(111) ;
diff --git a/src/repo/s6-rc-set-changestate.c b/src/repo/s6-rc-set-changestate.c
index 54aefd2..1064051 100644
--- a/src/repo/s6-rc-set-changestate.c
+++ b/src/repo/s6-rc-set-changestate.c
@@ -10,7 +10,6 @@
#include <skalibs/prog.h>
#include <skalibs/strerr.h>
#include <skalibs/gol.h>
-#include <skalibs/tai.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/djbunix.h>
@@ -126,7 +125,6 @@ int main (int argc, char const *const *argv)
fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ;
if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ;
- tain_now_g() ;
if (!s6rc_repo_makesvlist_byname(wgola[GOLA_REPODIR], argv[0], &storage, &svlist)) _exit(111) ;
list = genalloc_s(s6rc_repo_sv, &svlist) ;
diff --git a/src/repo/s6-rc-set-commit.c b/src/repo/s6-rc-set-commit.c
index 07ddbfb..9676f68 100644
--- a/src/repo/s6-rc-set-commit.c
+++ b/src/repo/s6-rc-set-commit.c
@@ -12,7 +12,6 @@
#include <skalibs/allreadwrite.h>
#include <skalibs/strerr.h>
#include <skalibs/gol.h>
-#include <skalibs/tai.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
#include <skalibs/djbunix.h>
@@ -47,7 +46,7 @@ static gol_arg const rgola[] =
{ .so = 'v', .lo = "verbosity", .i = GOLA_VERBOSITY },
{ .so = 'r', .lo = "repodir", .i = GOLA_REPODIR },
{ .so = 'D', .lo = "default-bundle", .i = GOLA_DEFBUNDLE },
- { .so = 'h', .lo = "fd-holder-user", .i = GOLA_FDHUSER }
+ { .so = 'h', .lo = "fdholder-user", .i = GOLA_FDHUSER }
} ;
static uint64_t wgolb = 0 ;
@@ -94,7 +93,6 @@ int main (int argc, char const *const *argv)
fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ;
if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ;
check_set(wgola[GOLA_REPODIR], argv[0]) ;
- tain_now_g() ;
size_t oldclen = S6RC_REPO_COMPILE_BUFLEN(strlen(wgola[GOLA_REPODIR]), strlen(argv[0])) ;
char oldc[oldclen] ;
diff --git a/src/repo/s6-rc-set-copy.c b/src/repo/s6-rc-set-copy.c
index 7961ca0..372a23c 100644
--- a/src/repo/s6-rc-set-copy.c
+++ b/src/repo/s6-rc-set-copy.c
@@ -9,7 +9,6 @@
#include <skalibs/prog.h>
#include <skalibs/strerr.h>
#include <skalibs/gol.h>
-#include <skalibs/tai.h>
#include <skalibs/djbunix.h>
#include <skalibs/unix-transactional.h>
@@ -125,7 +124,6 @@ int main (int argc, char const *const *argv)
fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ;
if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ;
- tain_now_g() ;
docopy(wgola[GOLA_REPODIR], argv[0], argv[1]) ;
_exit(0) ;
}
diff --git a/src/repo/s6-rc-set-delete.c b/src/repo/s6-rc-set-delete.c
index 48a81f0..d0d0f96 100644
--- a/src/repo/s6-rc-set-delete.c
+++ b/src/repo/s6-rc-set-delete.c
@@ -8,7 +8,6 @@
#include <skalibs/prog.h>
#include <skalibs/strerr.h>
#include <skalibs/gol.h>
-#include <skalibs/tai.h>
#include <skalibs/direntry.h>
#include <skalibs/djbunix.h>
@@ -110,7 +109,6 @@ int main (int argc, char const *const *argv)
fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ;
if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ;
- tain_now_g() ;
for (unsigned int i = 0 ; i < argc ; i++)
dodelete(wgola[GOLA_REPODIR], argv[i]) ;
diff --git a/src/repo/s6-rc-set-new.c b/src/repo/s6-rc-set-new.c
index bc72f92..04be39d 100644
--- a/src/repo/s6-rc-set-new.c
+++ b/src/repo/s6-rc-set-new.c
@@ -12,7 +12,6 @@
#include <skalibs/stat.h>
#include <skalibs/posixplz.h>
#include <skalibs/gol.h>
-#include <skalibs/tai.h>
#include <skalibs/prog.h>
#include <skalibs/strerr.h>
#include <skalibs/direntry.h>
@@ -121,7 +120,6 @@ int main (int argc, char const *const *argv)
}
fdlock = s6rc_repo_lock(wgola[GOLA_REPODIR], 1) ;
if (fdlock == -1) strerr_diefu2sys(111, "lock ", wgola[GOLA_REPODIR]) ;
- tain_now_g() ;
for (unsigned int i = 0 ; i < argc ; i++)
newset(wgola[GOLA_REPODIR], argv[i]) ;