aboutsummaryrefslogtreecommitdiffstats
path: root/src/repo/s6rc_repo_fix.c
blob: b379d30a6d41775459b99bbf114d85a6a6a863ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* ISC license. */

#include <string.h>
#include <stdlib.h>
#include <errno.h>

#include <skalibs/posixplz.h>
#include <skalibs/direntry.h>
#include <skalibs/strerr.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>

#include <s6-rc/repo.h>

int s6rc_repo_fix (char const *repo, uint32_t options, unsigned int verbosity)
{
  stralloc sa = STRALLOC_ZERO ;
  genalloc svlist = GENALLOC_ZERO ;  /* s6rc_repo_sv */
  genalloc badga = GENALLOC_ZERO ;  /* uint32_t */
  genalloc setind = GENALLOC_ZERO ;  /* size_t */
  int n ;

  if (verbosity >= 3)
    strerr_warni2x("checking set consistency in repository ", repo) ;

  n = s6rc_repo_list_sets(repo, &sa, &setind) ;
  if (n < 0)
  {
    strerr_warnfu1sys("list sets") ;
    return 0 ;
  }
  for (uint32_t i = 0 ; i < nsets ; i++)
  {
    if (verbosity >= 3)
      strerr_warni2x("checking set ", sa.s + genalloc_s(size_t, &setind)[i]) ;
    if (!s6rc_repo_fixset(repo, sa.s + genalloc_s(size_t, &setind)[i], options, verbosity, &sa, &svlist, &badga)) goto err ;
  }

  genalloc_free(s6rc_repo_sv, &svlist) ;
  genalloc_free(uint32_t, &badga) ;
  genalloc_free(size_t, &setind) ;
  stralloc_free(&sa) ;
  return 1 ;

 err:
  genalloc_free(s6rc_repo_sv, &svlist) ;
  genalloc_free(uint32_t, &badga) ;
  genalloc_free(size_t, &setind) ;
  stralloc_free(&sa) ;
  return 0 ;
}