Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
implement uncompressed meta.conf
Baptiste Daroussin committed 6 years ago
commit caf7e16b3e776c768971460676e1dc63f535a721
parent ffce85c
4 files changed +45 -14
modified libpkg/fetch.c
@@ -97,7 +97,7 @@ pkg_fetch_file_tmp(struct pkg_repo *repo, const char *url, char *dest,
		return(EPKG_FATAL);
	}

-
	retcode = pkg_fetch_file_to_fd(repo, url, fd, &t, 0, -1);
+
	retcode = pkg_fetch_file_to_fd(repo, url, fd, &t, 0, -1, false);

	if (t != 0) {
		struct timeval ftimes[2] = {
@@ -135,7 +135,7 @@ pkg_fetch_file(struct pkg_repo *repo, const char *url, char *dest, time_t t,
		return(EPKG_FATAL);
	}

-
	retcode = pkg_fetch_file_to_fd(repo, url, fd, &t, offset, size);
+
	retcode = pkg_fetch_file_to_fd(repo, url, fd, &t, offset, size, false);

	if (t != 0) {
		struct timeval ftimes[2] = {
@@ -455,7 +455,7 @@ ssh_cleanup:

int
pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest,
-
    time_t *t, ssize_t offset, int64_t size)
+
    time_t *t, ssize_t offset, int64_t size, bool silent)
{
	FILE		*remote = NULL;
	struct url	*u = NULL;
@@ -625,8 +625,9 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest,
			}
			--retry;
			if (retry <= 0 || fetchLastErrCode == FETCH_UNAVAIL) {
-
				pkg_emit_error("%s: %s", url,
-
				    fetchLastErrString);
+
				if (!silent)
+
					pkg_emit_error("%s: %s", url,
+
					    fetchLastErrString);
				retcode = EPKG_FATAL;
				goto cleanup;
			}
modified libpkg/pkg_repo.c
@@ -1,5 +1,5 @@
/*-
-
 * Copyright (c) 2011-2013 Baptiste Daroussin <bapt@FreeBSD.org>
+
 * Copyright (c) 2011-2019 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
 * Copyright (c) 2012-2015 Matthew Seaman <matthew@FreeBSD.org>
@@ -68,7 +68,7 @@ struct sig_cert {

static int
pkg_repo_fetch_remote_tmp(struct pkg_repo *repo,
-
		const char *filename, const char *extension, time_t *t, int *rc)
+
  const char *filename, const char *extension, time_t *t, int *rc, bool silent)
{
	char url[MAXPATHLEN];
	char tmp[MAXPATHLEN];
@@ -104,7 +104,7 @@ pkg_repo_fetch_remote_tmp(struct pkg_repo *repo,
	}
	(void)unlink(tmp);

-
	if ((*rc = pkg_fetch_file_to_fd(repo, url, fd, t, -1, 0)) != EPKG_OK) {
+
	if ((*rc = pkg_fetch_file_to_fd(repo, url, fd, t, -1, 0, silent)) != EPKG_OK) {
		close(fd);
		fd = -1;
	}
@@ -666,7 +666,7 @@ pkg_repo_fetch_remote_extract_fd(struct pkg_repo *repo, const char *filename,
	struct stat st;

	fd = pkg_repo_fetch_remote_tmp(repo, filename,
-
			packing_format_to_string(repo->meta->packing_format), t, rc);
+
	    packing_format_to_string(repo->meta->packing_format), t, rc, false);
	if (fd == -1)
		return (-1);

@@ -780,18 +780,29 @@ pkg_repo_fetch_meta(struct pkg_repo *repo, time_t *t)
	int rc = EPKG_OK, ret;
	struct sig_cert *sc = NULL, *s, *stmp;
	struct pkg_repo_check_cbdata cbdata;
+
	bool newscheme = false;

	dbdirfd = pkg_get_dbdirfd();
-
	fd = pkg_repo_fetch_remote_tmp(repo, "meta", "txz", t, &rc);
+
	snprintf(filepath, sizeof(filepath), "%s.meta", pkg_repo_name(repo));
+
	fd = pkg_repo_fetch_remote_tmp(repo, "meta", "conf", t, &rc, true);
+
	if (fd != -1) {
+
		newscheme = true;
+
		metafd = openat(dbdirfd, filepath, O_RDWR|O_CREAT|O_TRUNC, 0644);
+
		if (metafd == -1) {
+
			close(fd);
+
			return (EPKG_FATAL);
+
		}
+
		goto load_meta;
+
	}
+

+
	fd = pkg_repo_fetch_remote_tmp(repo, "meta", "txz", t, &rc, false);
	if (fd == -1)
		return (rc);

-
	snprintf(filepath, sizeof(filepath), "%s.meta", pkg_repo_name(repo));
-

	metafd = openat(dbdirfd, filepath, O_RDWR|O_CREAT|O_TRUNC, 0644);
	if (metafd == -1) {
		close(fd);
-
		return (rc);
+
		return (EPKG_FATAL);
	}

	if (pkg_repo_signature_type(repo) == SIG_PUBKEY) {
@@ -888,6 +899,8 @@ load_meta:
			munmap(map, st.st_size);

		return (rc);
+
	} else if (newscheme) {
+
		pkg_repo_meta_dump_fd(nmeta, fd);
	}

	if (repo->meta != NULL)
modified libpkg/pkg_repo_meta.c
@@ -1,4 +1,5 @@
/*-
+
 * Copyright (c) 2019 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2014 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
 *
@@ -314,6 +315,21 @@ pkg_repo_meta_version(ucl_object_t *top)
}

int
+
pkg_repo_meta_dump_fd(struct pkg_repo_meta *meta, const int fd)
+
{
+
	FILE *f;
+

+
	f = fdopen(dup(fd), "w+");
+
	if (f == NULL) {
+
		pkg_emit_error("Cannot dump file");
+
		return (EPKG_FATAL);
+
	}
+
	ucl_object_emit_file(pkg_repo_meta_to_ucl(meta), UCL_EMIT_JSON_COMPACT, f);
+
	fclose(f);
+
	return (EPKG_OK);
+
}
+

+
int
pkg_repo_meta_load(const int fd, struct pkg_repo_meta **target)
{
	struct ucl_parser *parser;
modified libpkg/private/pkg.h
@@ -670,11 +670,12 @@ int pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags);
#define PKG_DELETE_CONFLICT (1<<3)

int pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest,
-
    time_t *t, ssize_t offset, int64_t size);
+
    time_t *t, ssize_t offset, int64_t size, bool silent);
int pkg_repo_fetch_package(struct pkg *pkg);
int pkg_repo_mirror_package(struct pkg *pkg, const char *destdir);
int pkg_repo_fetch_remote_extract_fd(struct pkg_repo *repo,
    const char *filename, time_t *t, int *rc, size_t *sz);
+
int pkg_repo_meta_dump_fd(struct pkg_repo_meta *target, const int fd);
int pkg_repo_fetch_meta(struct pkg_repo *repo, time_t *t);

struct pkg_repo_meta *pkg_repo_meta_default(void);