Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add pkg_repoc.c and add entries in .gitignore.
jlaffaye committed 14 years ago
commit 65cf3f115c628dbc67f0dd64fbcb806e88bbe4ee
parent c2aa7d7
2 files changed +40 -0
modified .gitignore
@@ -7,6 +7,8 @@
*.core
*.gmon
*.log
+
*.gz
pkg/pkg
+
pkg2legacy
tests/test
docs/html/*
added libpkg/pkg_repo.c
@@ -0,0 +1,38 @@
+
#include <string.h>
+
#include <unistd.h>
+

+
#include "pkg.h"
+
#include "pkg_error.h"
+
#include "pkg_private.h"
+

+
int
+
pkg_repo_fetch(struct pkg *pkg, void *data, fetch_cb cb)
+
{
+
	char dest[MAXPATHLEN];
+
	char cksum[65];
+
	char *url;
+
	int retcode = EPKG_OK;
+

+
	if ((pkg->type & PKG_REMOTE) != PKG_REMOTE)
+
		return (ERROR_BAD_ARG("pkg"));
+

+
	snprintf(dest, sizeof(dest), "%s/%s", pkg_config("PKG_CACHEDIR"),
+
			 pkg_get(pkg, PKG_REPOPATH));
+

+
	/* If it is already in the local cachedir, dont bother to download it */
+
	if (access(dest, F_OK) == 0)
+
		goto checksum;
+

+
	asprintf(&url, "%s/%s", pkg_config("PACKAGESITE"),
+
			 pkg_get(pkg, PKG_REPOPATH));
+
	pkg_fetch_file(url, dest, data, cb);
+
	free(url);
+

+
	checksum:
+
	retcode = sha256_file(dest, cksum);
+
	if (retcode == EPKG_OK)
+
		if (strcmp(cksum, pkg_get(pkg, PKG_CKSUM)))
+
			retcode = pkg_error_set(EPKG_FATAL, "failed checksum");
+

+
	return (retcode);
+
}