Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use meta for names of repo files.
Vsevolod Stakhov committed 11 years ago
commit fec46587eac8391b402b0d8a18a916c714b2e383
parent 1c5efbf
9 files changed +80 -106
modified libpkg/Makefile.am
@@ -87,7 +87,6 @@ noinst_HEADERS= private/db_upgrades.h \
			private/pkg.h \
			private/pkg_printf.h \
			private/pkgdb.h \
-
			private/repodb.h \
			private/utils.h

SUBDIRS = repo .

\ No newline at end of file
modified libpkg/pkg_repo.c
@@ -55,8 +55,6 @@
#include "private/utils.h"
#include "private/pkg.h"
#include "private/pkgdb.h"
-
#include "private/repodb.h"
-


struct sig_cert {
	char name[MAXPATHLEN];
modified libpkg/pkg_repo_create.c
@@ -56,7 +56,6 @@
#include "private/utils.h"
#include "private/pkg.h"
#include "private/pkgdb.h"
-
#include "private/repodb.h"

struct digest_list_entry {
	char *origin;
@@ -202,7 +201,7 @@ pkg_create_repo_fts_free(struct pkg_fts_item *item)

static int
pkg_create_repo_read_fts(struct pkg_fts_item **items, FTS *fts,
-
	const char *repopath, size_t *plen)
+
	const char *repopath, size_t *plen, struct pkg_repo_meta *meta)
{
	FTSENT *fts_ent;
	struct pkg_fts_item *fts_cur;
@@ -220,19 +219,12 @@ pkg_create_repo_read_fts(struct pkg_fts_item **items, FTS *fts,
		if (ext == NULL)
			continue;

-
		if (strcmp(ext, ".tgz") != 0 &&
-
						strcmp(ext, ".tbz") != 0 &&
-
						strcmp(ext, ".txz") != 0 &&
-
						strcmp(ext, ".tar") != 0)
+
		if (strcmp(ext + 1, packing_format_to_string(meta->packing_format)) != 0)
			continue;

		*ext = '\0';

-
		if (strcmp(fts_ent->fts_name, repo_db_archive) == 0 ||
-
						strcmp(fts_ent->fts_name, repo_packagesite_archive) == 0 ||
-
						strcmp(fts_ent->fts_name, repo_filesite_archive) == 0 ||
-
						strcmp(fts_ent->fts_name, repo_digests_archive) == 0 ||
-
						strcmp(fts_ent->fts_name, repo_conflicts_archive) == 0) {
+
		if (pkg_repo_meta_is_special_file(fts_ent->fts_name, meta)) {
			*ext = '.';
			continue;
		}
@@ -559,7 +551,7 @@ pkg_create_repo(char *path, const char *output_dir, bool filelist,
	}

	snprintf(packagesite, sizeof(packagesite), "%s/%s", output_dir,
-
	    repo_packagesite_file);
+
	    meta->manifests);
	if ((fd = open(packagesite, O_CREAT|O_TRUNC|O_WRONLY, 00644)) == -1) {
		retcode = EPKG_FATAL;
		goto cleanup;
@@ -567,7 +559,7 @@ pkg_create_repo(char *path, const char *output_dir, bool filelist,
	close(fd);
	if (filelist) {
		snprintf(filesite, sizeof(filesite), "%s/%s", output_dir,
-
		    repo_filesite_file);
+
		    meta->filesite);
		if ((fd = open(packagesite, O_CREAT|O_TRUNC|O_WRONLY, 00644)) == -1) {
			retcode = EPKG_FATAL;
			goto cleanup;
@@ -575,7 +567,7 @@ pkg_create_repo(char *path, const char *output_dir, bool filelist,
		close(fd);
	}
	snprintf(repodb, sizeof(repodb), "%s/%s", output_dir,
-
	    repo_digests_file);
+
	    meta->digests);
	if ((mandigests = fopen(repodb, "w")) == NULL) {
		retcode = EPKG_FATAL;
		goto cleanup;
@@ -583,7 +575,7 @@ pkg_create_repo(char *path, const char *output_dir, bool filelist,

	len = 0;

-
	pkg_create_repo_read_fts(&fts_items, fts, path, &len);
+
	pkg_create_repo_read_fts(&fts_items, fts, path, &len, meta);

	if (len == 0) {
		/* Nothing to do */
@@ -800,7 +792,8 @@ done:

static int
pkg_repo_pack_db(const char *name, const char *archive, char *path,
-
		struct rsa_key *rsa, char **argv, int argc)
+
		struct rsa_key *rsa, struct pkg_repo_meta *meta,
+
		char **argv, int argc)
{
	struct packing *pack;
	unsigned char *sigret = NULL;
@@ -811,7 +804,7 @@ pkg_repo_pack_db(const char *name, const char *archive, char *path,
	sig = NULL;
	pub = NULL;

-
	if (packing_init(&pack, archive, TXZ) != EPKG_OK)
+
	if (packing_init(&pack, archive, meta->packing_format) != EPKG_OK)
		return (EPKG_FATAL);

	if (rsa != NULL) {
@@ -874,8 +867,9 @@ pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,
	char repo_path[MAXPATHLEN];
	char repo_archive[MAXPATHLEN];
	struct rsa_key *rsa = NULL;
+
	struct pkg_repo_meta *meta;
	struct stat st;
-
	int ret = EPKG_OK;
+
	int ret = EPKG_OK, nfile = 0;
	const int files_to_pack = 4;
	bool legacy = false;

@@ -897,65 +891,77 @@ pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,
	}

	pkg_emit_progress_start("Packing files for repository", output_dir);
-
	pkg_emit_progress_tick(0, files_to_pack);
+
	pkg_emit_progress_tick(nfile++, files_to_pack);

	snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
-
	    repo_packagesite_file);
+
		repo_meta_file);
+
	/*
+
	 * If no meta is defined, then it is a legacy repo
+
	 */
+
	if (access(repo_path, R_OK) != -1) {
+
		if (pkg_repo_meta_load(repo_path, &meta) != EPKG_OK) {
+
			pkg_emit_error("meta loading error while trying %s", repo_path);
+
			return (EPKG_FATAL);
+
		}
+
		else {
+
			meta = pkg_repo_meta_default();
+
		}
+
		if (pkg_repo_pack_db(repo_meta_file, repo_path, repo_path, rsa, meta,
+
			argv, argc) != EPKG_OK) {
+
			ret = EPKG_FATAL;
+
			goto cleanup;
+
		}
+
	}
+
	else {
+
		legacy = true;
+
		meta = pkg_repo_meta_default();
+
	}
+

+
	snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
+
	    meta->manifests);
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", output_dir,
-
	    repo_packagesite_archive);
-
	if (pkg_repo_pack_db(repo_packagesite_file, repo_archive, repo_path, rsa, argv, argc) != EPKG_OK) {
+
		meta->manifests_archive);
+
	if (pkg_repo_pack_db(meta->manifests, repo_archive, repo_path, rsa, meta,
+
		argv, argc) != EPKG_OK) {
		ret = EPKG_FATAL;
		goto cleanup;
	}

-
	pkg_emit_progress_tick(1, files_to_pack);
+
	pkg_emit_progress_tick(nfile++, files_to_pack);

	if (filelist) {
		snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
-
		    repo_filesite_file);
+
		    meta->filesite);
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s",
-
		    output_dir, repo_filesite_archive);
-
		if (pkg_repo_pack_db(repo_filesite_file, repo_archive, repo_path, rsa, argv, argc) != EPKG_OK) {
+
		    output_dir, meta->filesite_archive);
+
		if (pkg_repo_pack_db(meta->filesite, repo_archive, repo_path, rsa, meta,
+
			argv, argc) != EPKG_OK) {
			ret = EPKG_FATAL;
			goto cleanup;
		}
	}

-
	pkg_emit_progress_tick(2, files_to_pack);
+
	pkg_emit_progress_tick(nfile++, files_to_pack);

	snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
-
	    repo_digests_file);
+
	    meta->digests);
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", output_dir,
-
	    repo_digests_archive);
-
	if (pkg_repo_pack_db(repo_digests_file, repo_archive, repo_path, rsa, argv, argc) != EPKG_OK) {
+
	    meta->digests_archive);
+
	if (pkg_repo_pack_db(meta->digests, repo_archive, repo_path, rsa, meta,
+
		argv, argc) != EPKG_OK) {
		ret = EPKG_FATAL;
		goto cleanup;
	}

-
	snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
-
		repo_meta_file);
-
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", output_dir,
-
		repo_meta_archive);
-
	/*
-
	 * If no meta is defined, then it is a legacy repo
-
	 */
-
	if (access(repo_path, R_OK) != -1) {
-
		if (pkg_repo_pack_db(repo_meta_file, repo_archive, repo_path, rsa, argv, argc) != EPKG_OK) {
-
			ret = EPKG_FATAL;
-
			goto cleanup;
-
		}
-
	}
-
	else
-
		legacy = true;
-

-
	pkg_emit_progress_tick(3, files_to_pack);
+
	pkg_emit_progress_tick(nfile++, files_to_pack);

#if 0
	snprintf(repo_path, sizeof(repo_path), "%s/%s", output_dir,
-
		repo_conflicts_file);
+
		meta->conflicts);
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s", output_dir,
-
		repo_conflicts_archive);
-
	if (pkg_repo_pack_db(repo_conflicts_file, repo_archive, repo_path, rsa, argv, argc) != EPKG_OK) {
+
		meta->conflicts_archive);
+
	if (pkg_repo_pack_db(meta->conflicts, repo_archive, repo_path, rsa, meta,
+
		argv, argc) != EPKG_OK) {
		ret = EPKG_FATAL;
		goto cleanup;
	}
@@ -963,7 +969,7 @@ pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,

	/* Now we need to set the equal mtime for all archives in the repo */
	snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz",
-
	    output_dir, repo_db_archive);
+
	    output_dir, repo_meta_file);
	if (stat(repo_archive, &st) == 0) {
		struct timeval ftimes[2] = {
			{
@@ -976,25 +982,26 @@ pkg_finish_repo(const char *output_dir, pem_password_cb *password_cb,
			}
		};
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz",
-
		    output_dir, repo_packagesite_archive);
+
		    output_dir, meta->manifests_archive);
		utimes(repo_archive, ftimes);
		snprintf(repo_archive, sizeof(repo_archive), "%s/%s.txz",
-
		    output_dir, repo_digests_archive);
+
		    output_dir, meta->digests_archive);
		utimes(repo_archive, ftimes);
		if (filelist) {
			snprintf(repo_archive, sizeof(repo_archive),
-
			    "%s/%s.txz", output_dir, repo_filesite_archive);
+
			    "%s/%s.txz", output_dir, meta->filesite_archive);
			utimes(repo_archive, ftimes);
		}
		if (!legacy) {
			snprintf(repo_archive, sizeof(repo_archive),
-
				"%s/%s.txz", output_dir, repo_meta_archive);
+
				"%s/%s.txz", output_dir, repo_meta_file);
			utimes(repo_archive, ftimes);
		}
	}

cleanup:
	pkg_emit_progress_tick(files_to_pack, files_to_pack);
+
	pkg_repo_meta_free(meta);

	if (rsa)
		rsa_free(rsa);
modified libpkg/pkg_repo_meta.c
@@ -366,3 +366,20 @@ pkg_repo_meta_to_ucl(struct pkg_repo_meta *meta)

#undef META_EXPORT_FIELD
#undef META_EXPORT_FIELD_FUNC
+

+
#define META_SPECIAL_FILE(file, meta, field) \
+
	special || (meta->field == NULL ? false : (strcmp(file, meta->field) == 0))
+

+
bool
+
pkg_repo_meta_is_special_file(const char *file, struct pkg_repo_meta *meta)
+
{
+
	bool special = false;
+

+
	special = META_SPECIAL_FILE(file, meta, digests_archive);
+
	special = META_SPECIAL_FILE(file, meta, manifests_archive);
+
	special = META_SPECIAL_FILE(file, meta, filesite_archive);
+
	special = META_SPECIAL_FILE(file, meta, conflicts_archive);
+
	special = META_SPECIAL_FILE(file, meta, fulldb_archive);
+

+
	return (special);
+
}
modified libpkg/pkg_repo_update.c
@@ -45,7 +45,6 @@
#include "private/event.h"
#include "private/utils.h"
#include "private/pkgdb.h"
-
#include "private/repodb.h"
#include "private/pkg.h"

int
modified libpkg/private/pkg.h
@@ -491,6 +491,7 @@ struct pkg_repo_meta *pkg_repo_meta_default(void);
int pkg_repo_meta_load(const char *file, struct pkg_repo_meta **target);
void pkg_repo_meta_free(struct pkg_repo_meta *meta);
ucl_object_t * pkg_repo_meta_to_ucl(struct pkg_repo_meta *meta);
+
bool pkg_repo_meta_is_special_file(const char *file, struct pkg_repo_meta *meta);

typedef enum {
	HASH_UNKNOWN,
deleted libpkg/private/repodb.h
@@ -1,45 +0,0 @@
-
/*-
-
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
-
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
-
 * Copyright (c) 2013 Matthew Seaman <matthew@FreeBSD.org>
-
 * 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
-
 *    in this position and unchanged.
-
 * 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(S) ``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(S) 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.
-
 */
-

-
#ifndef _REPODB
-
#define _REPODB
-

-
static const char repo_db_file[] = "repo.sqlite";
-
static const char repo_db_archive[] = "repo";
-
static const char repo_packagesite_file[] = "packagesite.yaml";
-
static const char repo_packagesite_archive[] = "packagesite";
-
static const char repo_filesite_file[] = "filesite.yaml";
-
static const char repo_filesite_archive[] = "filesite";
-
static const char repo_digests_file[] = "digests";
-
static const char repo_digests_archive[] = "digests";
-
static const char repo_conflicts_file[] = "conflicts";
-
static const char repo_conflicts_archive[] = "conflicts";
-
static const char repo_meta_file[] = "meta";
-
static const char repo_meta_archive[] = "meta";
-

-
#endif	/* _REPODB */
modified libpkg/repo/binary/fetch.c
@@ -47,7 +47,6 @@
#include "private/event.h"
#include "private/utils.h"
#include "private/pkgdb.h"
-
#include "private/repodb.h"
#include "private/pkg.h"
#include "binary.h"

modified libpkg/repo/binary/update.c
@@ -43,7 +43,6 @@
#include "private/event.h"
#include "private/utils.h"
#include "private/pkgdb.h"
-
#include "private/repodb.h"
#include "private/pkg.h"
#include "binary.h"
#include "binary_private.h"