Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg_fetch_file now can take a time_t argument
Baptiste Daroussin committed 14 years ago
commit 915ebd48e70f42960569cb117bd7fe98afa7d35f
parent 7842acf
6 files changed +31 -8
modified libpkg/fetch.c
@@ -36,7 +36,7 @@
#include "private/event.h"

int
-
pkg_fetch_file(const char *url, const char *dest)
+
pkg_fetch_file(const char *url, const char *dest, time_t t)
{
	int fd = -1;
	FILE *remote = NULL;
@@ -67,6 +67,12 @@ pkg_fetch_file(const char *url, const char *dest)
			sleep(1);
		}
	}
+
	if (t != 0) {
+
		if (st.mtime <= t) {
+
			retcode = EPKG_UPTODATE;
+
			goto cleanup;
+
		}
+
	}

	begin_dl = time(NULL);
	while (done < st.size) {
modified libpkg/pkg.h
@@ -277,6 +277,10 @@ typedef enum {
	 * Can not create local database
	 */
	EPKG_ENODB,
+
	/**
+
	 * local file newer than remote
+
	 */
+
	EPKG_UPTODATE,
} pkg_error_t;

/**
@@ -778,7 +782,7 @@ int pkg_version_cmp(const char * const , const char * const);
 * Fetch a file.
 * @return An error code.
 */
-
int pkg_fetch_file(const char *url, const char *dest);
+
int pkg_fetch_file(const char *url, const char *dest, time_t t);

/* glue to deal with ports */
int ports_parse_plist(struct pkg *, char *);
modified libpkg/pkg_repo.c
@@ -108,7 +108,7 @@ pkg_repo_fetch(struct pkg *pkg)
	else
		snprintf(url, sizeof(url), "%s/%s", packagesite, repopath);

-
	retcode = pkg_fetch_file(url, dest);
+
	retcode = pkg_fetch_file(url, dest, 0);
	fetched = 1;

	if (retcode != EPKG_OK)
modified pkg/add.c
@@ -87,7 +87,7 @@ exec_add(int argc, char **argv)
	for (i = 1; i < argc; i++) {
		if (is_url(argv[i]) == EPKG_OK) {
			snprintf(path, sizeof(path), "./%s", basename(argv[i]));
-
			if ((retcode = pkg_fetch_file(argv[i], path)) != EPKG_OK)
+
			if ((retcode = pkg_fetch_file(argv[i], path, 0)) != EPKG_OK)
				break;

			file = path;
modified pkg/audit.c
@@ -26,6 +26,7 @@

#include <sys/param.h>
#include <sys/queue.h>
+
#include <sys/stat.h>

#define _WITH_GETLINE

@@ -81,10 +82,22 @@ fetch_and_extract(const char *src, const char *dest)
	const char *tmp = "/tmp/auditfile.tbz";
	int retcode = EPKG_FATAL;
	int ret;
+
	time_t t = 0;
+
	struct stat st;

-
	if (pkg_fetch_file(src, tmp) != EPKG_OK) {
-
		warnx("Can't fetch audit file");
-
		goto cleanup;
+
	if (stat(dest, &st) != -1) {
+
		t = st.st_mtime;
+
	}
+
	switch (pkg_fetch_file(src, tmp, t)) {
+
		case EPKG_OK:
+
			break;
+
		case EPKG_UPTODATE:
+
			printf("audit file uptodate\n");
+
			retcode = EPKG_OK;
+
			goto cleanup;
+
		default:
+
			warnx("Can't fetch audit file");
+
			goto cleanup;
	}

	a = archive_read_new();
modified pkg/update.c
@@ -74,7 +74,7 @@ update_from_remote_repo(const char *name, const char *url)
		return (EPKG_FATAL);
	}

-
	if (pkg_fetch_file(url, tmp) != EPKG_OK) {
+
	if (pkg_fetch_file(url, tmp, 0) != EPKG_OK) {
		/*
		 * No need to unlink(tmp) here as it is already
		 * done in pkg_fetch_file() in case fetch failed.