Ejemplo n.º 1
0
/**
 * Fetch repository calalogues.
 */
int
pkgcli_update(bool force) {
	int retcode = EPKG_FATAL;
	struct pkg_repo *r = NULL;

	/* Only auto update if the user has write access. */
	if (pkgdb_access(PKGDB_MODE_READ|PKGDB_MODE_WRITE|PKGDB_MODE_CREATE,
	    PKGDB_DB_REPO) == EPKG_ENOACCESS)
		return (EPKG_OK);

	if (!quiet)
		printf("Updating repository catalogue\n");

	while (pkg_repos(&r) == EPKG_OK) {
		if (!pkg_repo_enabled(r))
			continue;
		retcode = pkg_update(r, force);
		if (retcode == EPKG_UPTODATE) {
			if (!quiet)
				printf("%s repository catalogue is "
				       "up-to-date, no need to fetch "
				       "fresh copy\n", pkg_repo_ident(r));
				retcode = EPKG_OK;
		}
		if (retcode != EPKG_OK)
			break;
	}

	return (retcode);
}
Ejemplo n.º 2
0
/**
 * Fetch repository calalogues.
 */
int
pkgcli_update(bool force) {
	int retcode = EPKG_FATAL, update_count = 0;
	struct pkg_repo *r = NULL;

	/* Only auto update if the user has write access. */
	if (pkgdb_access(PKGDB_MODE_READ|PKGDB_MODE_WRITE|PKGDB_MODE_CREATE,
	    PKGDB_DB_REPO) == EPKG_ENOACCESS)
		return (EPKG_OK);

	if (!quiet)
		printf("Updating repository catalogue\n");

	if (pkg_repos_total_count() == 0) {
		fprintf(stderr, "No valid repository found.\n");
		return (EPKG_FATAL);
	}

	while (pkg_repos(&r) == EPKG_OK) {
		if (!pkg_repo_enabled(r))
			continue;
		retcode = pkg_update(r, force);
		if (retcode == EPKG_UPTODATE) {
			if (!quiet)
				printf("%s repository catalogue is "
				       "up-to-date, no need to fetch "
				       "fresh copy\n", pkg_repo_ident(r));
				retcode = EPKG_OK;
		}
		if (retcode != EPKG_OK)
			break;
		update_count ++;
	}

	if (!quiet && update_count == 0)
		printf("No repositories are enabled\n");

	return (retcode);
}
Ejemplo n.º 3
0
Archivo: update.c Proyecto: renchap/pkg
static int
pkg_update_full(const char *repofile, struct pkg_repo *repo, time_t *mtime)
{
	char repofile_unchecked[MAXPATHLEN];
	int fd = -1, rc = EPKG_FATAL;
	sqlite3 *sqlite = NULL;
	char *req = NULL;
	char *bad_abis = NULL;
	const char *myarch;

	snprintf(repofile_unchecked, sizeof(repofile_unchecked),
			"%s.unchecked", repofile);

	/* If the repo.sqlite file exists, test that we can write to
		   it.  If it doesn't exist, assume we can create it */

	if (eaccess(repofile, F_OK) == 0 && eaccess(repofile, W_OK) == -1) {
		pkg_emit_error("Insufficient privilege to update %s\n",
				repofile);
		rc = EPKG_ENOACCESS;
		goto cleanup;
	}

	if ((fd = repo_fetch_remote_tmp(repo, repo_db_archive, "txz", mtime, &rc)) == -1) {
		goto cleanup;
	}

	if ((rc = repo_archive_extract_file(fd, repo_db_file, repofile_unchecked, repo->pubkey, -1)) != EPKG_OK) {
		goto cleanup;
	}

	/* check if the repository is for valid architecture */
	if (access(repofile_unchecked, R_OK|W_OK) == -1) {
		pkg_emit_error("Archive file does not have repo.sqlite file");
		rc = EPKG_FATAL;
		goto cleanup;
	}
	if (sqlite3_open(repofile_unchecked, &sqlite) != SQLITE_OK) {
		unlink(repofile_unchecked);
		pkg_emit_error("Corrupted repository");
		rc = EPKG_FATAL;
		goto cleanup;
	}

	pkg_config_string(PKG_CONFIG_ABI, &myarch);

	req = sqlite3_mprintf("select group_concat(arch, ', ') from "
			"(select distinct arch from packages "
			"where arch not GLOB '%q')", myarch);
	if (get_sql_string(sqlite, req, &bad_abis) != EPKG_OK) {
		sqlite3_free(req);
		pkg_emit_error("Unable to query repository");
		rc = EPKG_FATAL;
		sqlite3_close(sqlite);
		goto cleanup;
	}

	if (bad_abis != NULL) {
		pkg_emit_error("At least one of the packages provided by "
				"the repository is not compatible with your ABI:\n"
				"    Your ABI: %s\n"
				"    Incompatible ABIs found: %s",
				myarch, bad_abis);
		rc = EPKG_FATAL;
		sqlite3_close(sqlite);
		goto cleanup;
	}

	/* register the packagesite */
	if (pkg_register_repo(repo, sqlite) != EPKG_OK) {
		sqlite3_close(sqlite);
		goto cleanup;
	}

	sqlite3_close(sqlite);
	sqlite3_shutdown();

	if (rename(repofile_unchecked, repofile) != 0) {
		pkg_emit_errno("rename", "");
		rc = EPKG_FATAL;
		goto cleanup;
	}

	if ((rc = remote_add_indexes(pkg_repo_ident(repo))) != EPKG_OK)
		goto cleanup;
	rc = EPKG_OK;

	cleanup:
	if (fd != -1)
		(void)close(fd);

	return (rc);
}