Use a single file to store repository data.

This is just the starting point to extend repositories with PGP signatures.
This commit is contained in:
Juan RP
2013-06-10 10:28:39 +02:00
parent fa9d3471d9
commit 99be698979
28 changed files with 666 additions and 548 deletions

View File

@@ -468,34 +468,6 @@ process_entry_file(struct archive *ar,
write_entry(ar, sparse_entry);
}
static void
process_entry_memory(struct archive *ar, const void *src, const char *file)
{
struct archive_entry *entry;
time_t tm;
assert(ar);
assert(src);
assert(file);
tm = time(NULL);
entry = archive_entry_new();
assert(entry);
archive_entry_set_filetype(entry, AE_IFREG);
archive_entry_set_perm(entry, 0644);
archive_entry_set_uname(entry, "root");
archive_entry_set_gname(entry, "root");
archive_entry_set_pathname(entry, file);
archive_entry_set_size(entry, strlen(src));
archive_entry_set_atime(entry, tm, 0);
archive_entry_set_mtime(entry, tm, 0);
archive_entry_set_ctime(entry, tm, 0);
archive_write_header(ar, entry);
archive_write_data(ar, src, strlen(src));
archive_entry_free(entry);
}
static void
process_archive(struct archive *ar,
struct archive_entry_linkresolver *resolver,
@@ -517,13 +489,15 @@ process_archive(struct archive *ar,
/* Add props.plist metadata file */
xml = prop_dictionary_externalize(pkg_propsd);
assert(xml);
process_entry_memory(ar, xml, "./props.plist");
xbps_archive_append_buf(ar, xml, strlen(xml), "./props.plist",
0644, "root", "root");
free(xml);
/* Add files.plist metadata file */
xml = prop_dictionary_externalize(pkg_filesd);
assert(xml);
process_entry_memory(ar, xml, "./files.plist");
xbps_archive_append_buf(ar, xml, strlen(xml), "./files.plist",
0644, "root", "root");
free(xml);
/* Add all package data files and release resources */

View File

@@ -201,13 +201,9 @@ main(int argc, char **argv)
}
}
/* Sync remote repository index files by default */
/* Sync remote repository data by default */
if (sync && !drun) {
rv = xbps_rpool_sync(&xh, XBPS_PKGINDEX, NULL);
if (rv != 0)
exit(rv);
rv = xbps_rpool_sync(&xh, XBPS_PKGINDEX_FILES, NULL);
if (rv != 0)
if ((rv = xbps_rpool_sync(&xh, NULL)) != 0)
exit(rv);
}

View File

@@ -162,13 +162,13 @@ list_pkgs_pkgdb(struct xbps_handle *xhp)
}
static int
repo_list_uri_cb(struct xbps_rindex *rpi, void *arg, bool *done)
repo_list_uri_cb(struct xbps_repo *repo, void *arg, bool *done)
{
(void)arg;
(void)done;
printf("%s (%zu packages)\n", rpi->uri,
(size_t)prop_dictionary_count(rpi->repod));
printf("%s (%zu packages)\n", repo->uri,
(size_t)prop_dictionary_count(repo->idx));
return 0;
}

View File

@@ -123,21 +123,18 @@ ownedby(struct xbps_handle *xhp, int npatterns, char **patterns)
}
static void
repo_match_files_by_pattern(prop_dictionary_t pkgd,
struct ffdata *ffd)
repo_match_files_by_pattern(prop_array_t files,
const char *pkgver,
struct ffdata *ffd)
{
prop_array_t array;
const char *filestr, *pkgver;
const char *filestr;
size_t i;
int x;
array = prop_dictionary_get(pkgd, "files");
for (i = 0; i < prop_array_count(array); i++) {
prop_array_get_cstring_nocopy(array, i, &filestr);
for (i = 0; i < prop_array_count(files); i++) {
prop_array_get_cstring_nocopy(files, i, &filestr);
for (x = 0; x < ffd->npatterns; x++) {
if ((fnmatch(ffd->patterns[x], filestr, FNM_PERIOD)) == 0) {
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
printf("%s: %s (%s)\n",
pkgver, filestr, ffd->repouri);
}
@@ -146,35 +143,26 @@ repo_match_files_by_pattern(prop_dictionary_t pkgd,
}
static int
repo_ownedby_cb(struct xbps_rindex *rpi, void *arg, bool *done)
repo_ownedby_cb(struct xbps_repo *repo, void *arg, bool *done)
{
prop_array_t allkeys;
prop_dictionary_t pkgd, idxfiles;
prop_array_t allkeys, pkgar;
prop_dictionary_t filesd;
prop_dictionary_keysym_t ksym;
struct ffdata *ffd = arg;
char *plist;
const char *pkgver;
unsigned int i;
(void)done;
if ((plist = xbps_pkg_index_files_plist(rpi->xhp, rpi->uri)) == NULL)
return ENOMEM;
if ((idxfiles = prop_dictionary_internalize_from_zfile(plist)) == NULL) {
if (errno == ENOENT) {
fprintf(stderr, "%s: index-files missing! "
"ignoring...\n", rpi->uri);
return 0;
}
return errno;
}
ffd->repouri = rpi->uri;
allkeys = prop_dictionary_all_keys(idxfiles);
filesd = xbps_repo_get_plist(repo, XBPS_PKGINDEX_FILES);
ffd->repouri = repo->uri;
allkeys = prop_dictionary_all_keys(filesd);
for (i = 0; i < prop_array_count(allkeys); i++) {
ksym = prop_array_get(allkeys, i);
pkgd = prop_dictionary_get_keysym(idxfiles, ksym);
repo_match_files_by_pattern(pkgd, ffd);
pkgar = prop_dictionary_get_keysym(filesd, ksym);
pkgver = prop_dictionary_keysym_cstring_nocopy(ksym);
repo_match_files_by_pattern(pkgar, pkgver, ffd);
}
return 0;

View File

@@ -96,7 +96,7 @@ print_results(struct xbps_handle *xhp, struct search_data *sd)
}
static int
search_pkgs_cb(struct xbps_rindex *rpi, void *arg, bool *done)
search_pkgs_cb(struct xbps_repo *repo, void *arg, bool *done)
{
prop_array_t allkeys;
prop_dictionary_t pkgd;
@@ -108,12 +108,12 @@ search_pkgs_cb(struct xbps_rindex *rpi, void *arg, bool *done)
(void)done;
allkeys = prop_dictionary_all_keys(rpi->repod);
allkeys = prop_dictionary_all_keys(repo->idx);
for (i = 0; i < prop_array_count(allkeys); i++) {
prop_array_t provides = NULL;
ksym = prop_array_get(allkeys, i);
pkgd = prop_dictionary_get_keysym(rpi->repod, ksym);
pkgd = prop_dictionary_get_keysym(repo->idx, ksym);
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(pkgd, "short_desc", &desc);

View File

@@ -128,7 +128,7 @@ repo_show_pkg_deps(struct xbps_handle *xhp, const char *pattern, bool full)
}
static int
repo_revdeps_cb(struct xbps_rindex *rpi, void *arg, bool *done)
repo_revdeps_cb(struct xbps_repo *repo, void *arg, bool *done)
{
prop_dictionary_t pkgd;
prop_array_t pkgdeps;
@@ -138,10 +138,10 @@ repo_revdeps_cb(struct xbps_rindex *rpi, void *arg, bool *done)
(void)done;
iter = prop_dictionary_iterator(rpi->repod);
iter = prop_dictionary_iterator(repo->idx);
assert(iter);
while ((obj = prop_object_iterator_next(iter))) {
pkgd = prop_dictionary_get_keysym(rpi->repod, obj);
pkgd = prop_dictionary_get_keysym(repo->idx, obj);
pkgdeps = prop_dictionary_get(pkgd, "run_depends");
if (pkgdeps == NULL || prop_array_count(pkgdeps) == 0)
continue;
@@ -149,7 +149,7 @@ repo_revdeps_cb(struct xbps_rindex *rpi, void *arg, bool *done)
if (xbps_match_pkgdep_in_array(pkgdeps, pattern)) {
prop_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch);
if (xbps_pkg_arch_match(rpi->xhp, arch, NULL)) {
if (xbps_pkg_arch_match(repo->xhp, arch, NULL)) {
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
printf("%s\n", pkgver);

View File

@@ -2,7 +2,7 @@ TOPDIR = ../..
-include $(TOPDIR)/config.mk
BIN = xbps-rindex
OBJS = main.o index-add.o index-clean.o remove-obsoletes.o
OBJS = main.o index-add.o index-clean.o remove-obsoletes.o repoflush.o
MAN = $(BIN).8
include $(TOPDIR)/mk/prog.mk

View File

@@ -41,4 +41,8 @@ int index_files_clean(struct xbps_handle *, const char *);
/* From remove-obsoletes.c */
int remove_obsoletes(struct xbps_handle *, const char *);
/* From repoflush.c */
int repodata_flush(struct xbps_handle *, const char *,
prop_dictionary_t, prop_dictionary_t);
#endif /* !_XBPS_RINDEX_DEFS_H_ */

View File

@@ -32,8 +32,11 @@
#include <dirent.h>
#include <libgen.h>
#include <assert.h>
#include <fcntl.h>
#include <xbps_api.h>
#include <archive.h>
#include <archive_entry.h>
#include "defs.h"
/*
@@ -45,56 +48,37 @@ index_add(struct xbps_handle *xhp, int argc, char **argv, bool force)
{
prop_array_t filespkgar, pkg_files, pkg_links, pkg_cffiles;
prop_dictionary_t idx, idxfiles, newpkgd, newpkgfilesd, curpkgd;
prop_dictionary_t filespkgd;
prop_object_t obj, fileobj;
struct xbps_repo *repo;
struct stat st;
const char *oldpkgver, *arch, *oldarch;
char *pkgver, *pkgname, *sha256, *repodir, *buf;
char *tmprepodir, *plist, *plistf;
char *tmprepodir;
size_t x;
int i, ret = 0;
bool files_flush = false, found = false, flush = false;
int i, rv, ret = 0;
bool flush = false, found = false;
idx = idxfiles = newpkgd = newpkgfilesd = curpkgd = NULL;
tmprepodir = plist = plistf = NULL;
if ((tmprepodir = strdup(argv[0])) == NULL)
return ENOMEM;
/*
* Read the repository data or create index dictionaries otherwise.
*/
repodir = dirname(tmprepodir);
/* Internalize index or create it if doesn't exist */
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL) {
free(tmprepodir);
return -1;
}
if ((idx = prop_dictionary_internalize_from_zfile(plist)) == NULL) {
if (errno != ENOENT) {
fprintf(stderr, "index: cannot read `%s': %s\n",
plist, strerror(errno));
return -1;
} else {
idx = prop_dictionary_create();
assert(idx);
}
}
/* Internalize index-files or create it if doesn't exist */
if ((plistf = xbps_pkg_index_files_plist(xhp, repodir)) == NULL)
return -1;
free(tmprepodir);
if ((idxfiles = prop_dictionary_internalize_from_zfile(plistf)) == NULL) {
if (errno != ENOENT) {
fprintf(stderr, "index: cannot read `%s': %s\n",
plistf, strerror(errno));
return -1;
} else {
idxfiles = prop_dictionary_create();
assert(idx);
}
repo = xbps_repo_open(xhp, repodir);
if (repo != NULL) {
idx = xbps_repo_get_plist(repo, XBPS_PKGINDEX);
idxfiles = xbps_repo_get_plist(repo, XBPS_PKGINDEX_FILES);
}
if (idx == NULL)
idx = prop_dictionary_create();
if (idxfiles == NULL)
idxfiles = prop_dictionary_create();
if (repo != NULL)
xbps_repo_close(repo);
/*
* Process all packages specified in argv.
@@ -212,7 +196,6 @@ index_add(struct xbps_handle *xhp, int argc, char **argv, bool force)
free(pkgname);
return EINVAL;
}
flush = true;
printf("index: added `%s' (%s).\n", pkgver, arch);
/*
@@ -284,43 +267,29 @@ index_add(struct xbps_handle *xhp, int argc, char **argv, bool force)
}
prop_object_release(newpkgfilesd);
/* create pkg dictionary */
filespkgd = prop_dictionary_create();
assert(filespkgd);
/* add pkg files array into pkg dictionary */
prop_dictionary_set(filespkgd, "files", filespkgar);
/* add pkg files array into index-files */
prop_dictionary_set(idxfiles, pkgver, filespkgar);
prop_object_release(filespkgar);
/* set pkgver obj into pkg dictionary */
prop_dictionary_set_cstring(filespkgd, "pkgver", pkgver);
/* add pkg dictionary into index-files */
prop_dictionary_set(idxfiles, pkgname, filespkgd);
prop_object_release(filespkgd);
printf("index-files: added `%s' (%s)\n", pkgver, arch);
files_flush = true;
prop_object_release(newpkgd);
free(pkgver);
free(pkgname);
}
if (flush && !prop_dictionary_externalize_to_zfile(idx, plist)) {
fprintf(stderr, "index: failed to externalize plist: %s\n",
strerror(errno));
return -1;
}
if (files_flush &&
!prop_dictionary_externalize_to_zfile(idxfiles, plistf)) {
fprintf(stderr, "index-files: failed to externalize "
"plist: %s\n", strerror(errno));
return -1;
/*
* Generate repository data file.
*/
if (flush) {
rv = repodata_flush(xhp, repodir, idx, idxfiles);
if (rv != 0)
return rv;
}
printf("index: %u packages registered.\n",
prop_dictionary_count(idx));
printf("index-files: %u packages registered.\n",
prop_dictionary_count(idxfiles));
prop_object_release(idx);
prop_object_release(idxfiles);
return 0;
}

View File

@@ -33,6 +33,7 @@
#include <libgen.h>
#include <assert.h>
#include <pthread.h>
#include <fcntl.h>
#include <xbps_api.h>
#include "defs.h"
@@ -99,8 +100,10 @@ cleaner_files_thread(void *arg)
{
prop_object_t obj;
prop_array_t array;
prop_dictionary_t ipkgd;
struct thread_data *thd = arg;
const char *pkgname;
const char *pkgver, *ipkgver;
char *pkgname;
unsigned int i;
/* process pkgs from start until end */
@@ -108,10 +111,20 @@ cleaner_files_thread(void *arg)
for (i = thd->start; i < thd->end; i++) {
obj = prop_array_get(array, i);
pkgname = prop_dictionary_keysym_cstring_nocopy(obj);
pkgver = prop_dictionary_keysym_cstring_nocopy(obj);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
ipkgd = prop_dictionary_get(thd->idx, pkgname);
/* If pkg is not registered in index, remove it */
if (!prop_dictionary_get(thd->idx, pkgname))
prop_array_add_cstring_nocopy(thd->result_files, pkgname);
if (ipkgd == NULL)
prop_array_add_cstring_nocopy(thd->result_files, pkgver);
/* if another version is registered in index, remove it */
else {
prop_dictionary_get_cstring_nocopy(ipkgd, "pkgver", &ipkgver);
if (strcmp(ipkgver, pkgver))
prop_array_add_cstring_nocopy(thd->result_files, pkgver);
}
free(pkgname);
}
prop_object_release(array);
@@ -125,36 +138,28 @@ cleaner_files_thread(void *arg)
int
index_clean(struct xbps_handle *xhp, const char *repodir)
{
struct xbps_repo *repo;
struct thread_data *thd;
prop_dictionary_t idx, idxfiles;
const char *keyname;
char *plist, *plistf, *pkgname;
char *pkgname;
size_t x, pkgcount, slicecount;
int i, maxthreads, rv = 0;
bool flush = false;
plist = xbps_pkg_index_plist(xhp, repodir);
assert(plist);
plistf = xbps_pkg_index_files_plist(xhp, repodir);
assert(plistf);
idx = prop_dictionary_internalize_from_zfile(plist);
if (idx == NULL) {
if (errno != ENOENT) {
fprintf(stderr, "index: cannot read `%s': %s\n",
plist, strerror(errno));
return -1;
} else
repo = xbps_repo_open(xhp, repodir);
if (repo == NULL) {
if (errno == ENOENT)
return 0;
fprintf(stderr, "index: cannot read repository data: %s\n", strerror(errno));
return -1;
}
idxfiles = prop_dictionary_internalize_from_zfile(plistf);
if (idxfiles == NULL) {
if (errno != ENOENT) {
fprintf(stderr, "index: cannot read `%s': %s\n",
plistf, strerror(errno));
return -1;
} else
return 0;
idx = xbps_repo_get_plist(repo, XBPS_PKGINDEX);
idxfiles = xbps_repo_get_plist(repo, XBPS_PKGINDEX_FILES);
xbps_repo_close(repo);
if (idx == NULL || idxfiles == NULL) {
fprintf(stderr, "incomplete repository data file!");
return -1;
}
if (chdir(repodir) == -1) {
fprintf(stderr, "index: cannot chdir to %s: %s\n",
@@ -216,7 +221,7 @@ index_clean(struct xbps_handle *xhp, const char *repodir)
printf("index: removed entry %s\n", keyname);
pkgname = xbps_pkg_name(keyname);
prop_dictionary_remove(idx, pkgname);
prop_dictionary_remove(idxfiles, pkgname);
prop_dictionary_remove(idxfiles, keyname);
free(pkgname);
flush = true;
}
@@ -228,23 +233,17 @@ index_clean(struct xbps_handle *xhp, const char *repodir)
flush = true;
}
}
if (!flush)
goto out;
if (!prop_dictionary_externalize_to_zfile(idx, plist))
fprintf(stderr, "index: failed to externalize %s: %s\n",
plist, strerror(errno));
if (!prop_dictionary_externalize_to_zfile(idxfiles, plistf))
fprintf(stderr, "index-files: failed to externalize %s: %s\n",
plistf, strerror(errno));
out:
if (flush) {
rv = repodata_flush(xhp, repodir, idx, idxfiles);
if (rv != 0)
return rv;
}
printf("index: %u packages registered.\n",
prop_dictionary_count(idx));
printf("index-files: %u packages registered.\n",
prop_dictionary_count(idxfiles));
prop_object_release(idx);
prop_object_release(idxfiles);
return rv;
}

View File

@@ -40,7 +40,7 @@
struct thread_data {
pthread_t thread;
prop_array_t array;
struct xbps_rindex *ri;
struct xbps_repo *repo;
unsigned int start;
unsigned int end;
int thread_num;
@@ -95,7 +95,7 @@ cleaner_thread(void *arg)
prop_array_get_cstring_nocopy(thd->array, i, &binpkg);
pkgd = xbps_get_pkg_plist_from_binpkg(binpkg, "./props.plist");
if (pkgd == NULL) {
rv = remove_pkg(thd->ri->uri, arch, binpkg);
rv = remove_pkg(thd->repo->uri, arch, binpkg);
if (rv != 0) {
prop_object_release(pkgd);
continue;
@@ -105,17 +105,17 @@ cleaner_thread(void *arg)
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch);
/* ignore pkgs from other archs */
if (!xbps_pkg_arch_match(thd->ri->xhp, arch, NULL)) {
if (!xbps_pkg_arch_match(thd->repo->xhp, arch, NULL)) {
prop_object_release(pkgd);
continue;
}
xbps_dbg_printf(thd->ri->xhp, "thread[%d] checking %s (%s)\n",
xbps_dbg_printf(thd->repo->xhp, "thread[%d] checking %s (%s)\n",
thd->thread_num, pkgver, binpkg);
/*
* If binpkg is not registered in index, remove binpkg.
*/
if (!xbps_rindex_get_pkg(thd->ri, pkgver)) {
rv = remove_pkg(thd->ri->uri, arch, binpkg);
if (!xbps_repo_get_pkg(thd->repo, pkgver)) {
rv = remove_pkg(thd->repo->uri, arch, binpkg);
if (rv != 0) {
prop_object_release(pkgd);
continue;
@@ -131,33 +131,28 @@ cleaner_thread(void *arg)
int
remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
{
prop_dictionary_t idx;
prop_array_t array = NULL;
struct xbps_rindex ri;
struct xbps_repo *repo;
struct thread_data *thd;
DIR *dirp;
struct dirent *dp;
char *plist, *ext;
char *ext;
int i, maxthreads, rv = 0;
size_t slicecount, pkgcount;
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL)
return -1;
idx = prop_dictionary_internalize_from_zfile(plist);
if (idx == NULL) {
repo = xbps_repo_open(xhp, repodir);
if (repo == NULL) {
if (errno != ENOENT) {
fprintf(stderr, "xbps-rindex: cannot read `%s': %s\n",
plist, strerror(errno));
fprintf(stderr, "xbps-rindex: cannot read repository data: %s\n",
strerror(errno));
return -1;
} else
return 0;
}
return 0;
}
if ((repo->idx = xbps_repo_get_plist(repo, XBPS_PKGINDEX)) == NULL) {
xbps_repo_close(repo);
return -1;
}
/* initialize repository index */
ri.repod = idx;
ri.uri = repodir;
ri.xhp = xhp;
if (chdir(repodir) == -1) {
fprintf(stderr, "xbps-rindex: cannot chdir to %s: %s\n",
repodir, strerror(errno));
@@ -191,7 +186,7 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
for (i = 0; i < maxthreads; i++) {
thd[i].thread_num = i;
thd[i].array = array;
thd[i].ri = &ri;
thd[i].repo = repo;
thd[i].start = pkgcount;
if (i + 1 >= maxthreads)
thd[i].end = prop_array_count(array);
@@ -205,5 +200,7 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
for (i = 0; i < maxthreads; i++)
pthread_join(thd[i].thread, NULL);
xbps_repo_close(repo);
return rv;
}

View File

@@ -0,0 +1,94 @@
/*-
* Copyright (c) 2013 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/stat.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
#include <libgen.h>
#include <assert.h>
#include <fcntl.h>
#include <xbps_api.h>
#include "defs.h"
int
repodata_flush(struct xbps_handle *xhp, const char *repodir,
prop_dictionary_t idx, prop_dictionary_t idxfiles)
{
struct archive *ar;
mode_t myumask;
char *repofile, *tname, *xml;
int repofd;
/* Create a tempfile for our repository archive */
repofile = xbps_repo_path(xhp, repodir);
tname = xbps_xasprintf("%s.XXXXXXXXXX", repofile);
if ((repofd = mkstemp(tname)) == -1)
return errno;
/* Create and write our repository archive */
ar = archive_write_new();
assert(ar);
archive_write_add_filter_gzip(ar);
archive_write_set_format_pax_restricted(ar);
archive_write_set_options(ar, "compression-level=9");
archive_write_open_fd(ar, repofd);
xml = prop_dictionary_externalize(idx);
assert(xml);
if (xbps_archive_append_buf(ar, xml, strlen(xml),
XBPS_PKGINDEX, 0644, "root", "root") != 0) {
free(xml);
return -1;
}
free(xml);
xml = prop_dictionary_externalize(idxfiles);
assert(xml);
if (xbps_archive_append_buf(ar, xml, strlen(xml),
XBPS_PKGINDEX_FILES, 0644, "root", "root") != 0) {
free(xml);
return -1;
}
free(xml);
archive_write_free(ar);
/* Write data to tempfile and rename */
fdatasync(repofd);
myumask = umask(0);
(void)umask(myumask);
assert(fchmod(repofd, 0666 & ~myumask) != -1);
close(repofd);
rename(tname, repofile);
free(repofile);
free(tname);
return 0;
}