Skip to content

Commit

Permalink
Fetch, parse and use remote repo metafile.
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Apr 15, 2014
1 parent 5d71e04 commit f710369
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 16 deletions.
67 changes: 60 additions & 7 deletions libpkg/pkg_repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,21 @@ pkg_repo_fetch_remote_tmp(struct pkg_repo *repo,
char tmp[MAXPATHLEN];
int fd;
mode_t mask;
const char *tmpdir;
const char *tmpdir, *dot;

snprintf(url, sizeof(url), "%s/%s.%s", pkg_repo_url(repo), filename, extension);
/*
* XXX: here we support old naming scheme, such as filename.yaml
*/
dot = strrchr(filename, '.');
if (dot != NULL) {
snprintf(tmp, MIN(sizeof(tmp), dot - filename + 1), "%s", filename);
snprintf(url, sizeof(url), "%s/%s.%s", pkg_repo_url(repo), tmp,
extension);
}
else {
snprintf(url, sizeof(url), "%s/%s.%s", pkg_repo_url(repo), filename,
extension);
}

tmpdir = getenv("TMPDIR");
if (tmpdir == NULL)
Expand Down Expand Up @@ -443,24 +455,24 @@ pkg_repo_archive_extract_file(int fd, const char *file,
}

FILE *
pkg_repo_fetch_remote_extract_tmp(struct pkg_repo *repo, const char *filename,
const char *extension, time_t *t, int *rc, const char *archive_file)
pkg_repo_fetch_remote_extract_tmp(struct pkg_repo *repo, const char *filename, time_t *t, int *rc)
{
int fd, dest_fd;
mode_t mask;
FILE *res = NULL;
const char *tmpdir;
char tmp[MAXPATHLEN];

fd = pkg_repo_fetch_remote_tmp(repo, filename, extension, t, rc);
fd = pkg_repo_fetch_remote_tmp(repo, filename,
packing_format_to_string(repo->meta->packing_format), t, rc);
if (fd == -1) {
return (NULL);
}

tmpdir = getenv("TMPDIR");
if (tmpdir == NULL)
tmpdir = "/tmp";
snprintf(tmp, sizeof(tmp), "%s/%s.XXXXXX", tmpdir, archive_file);
snprintf(tmp, sizeof(tmp), "%s/%s.XXXXXX", tmpdir, filename);

mask = umask(022);
dest_fd = mkstemp(tmp);
Expand All @@ -472,7 +484,7 @@ pkg_repo_fetch_remote_extract_tmp(struct pkg_repo *repo, const char *filename,
goto cleanup;
}
(void)unlink(tmp);
if (pkg_repo_archive_extract_file(fd, archive_file, NULL, repo, dest_fd) != EPKG_OK) {
if (pkg_repo_archive_extract_file(fd, filename, NULL, repo, dest_fd) != EPKG_OK) {
*rc = EPKG_FATAL;
goto cleanup;
}
Expand All @@ -494,6 +506,47 @@ pkg_repo_fetch_remote_extract_tmp(struct pkg_repo *repo, const char *filename,
return (res);
}

int
pkg_repo_fetch_meta(struct pkg_repo *repo, time_t *t)
{
char filepath[MAXPATHLEN];
struct pkg_repo_meta *nmeta;
const char *dbdir = NULL;
int fd;
int rc = EPKG_OK;

dbdir = pkg_object_string(pkg_config_get("PKG_DBDIR"));

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

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

/* Remove old metafile */
if (unlink (filepath) == -1 && errno != ENOENT) {
close(fd);
return (EPKG_FATAL);
}

if ((rc = pkg_repo_archive_extract_file(fd, "meta", filepath, repo, -1)) != EPKG_OK) {
close (fd);
return (rc);
}

close(fd);

if ((rc = pkg_repo_meta_load(filepath, &nmeta)) != EPKG_OK)
return (rc);

if (repo->meta != NULL)
pkg_repo_meta_free(repo->meta);

repo->meta = nmeta;

return (rc);
}

static struct fingerprint *
pkg_repo_parse_fingerprint(ucl_object_t *obj)
{
Expand Down
2 changes: 1 addition & 1 deletion libpkg/pkg_repo_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pkg_repo_meta_set_default(struct pkg_repo_meta *meta)

/* Not use conflicts for now */
meta->conflicts = NULL;
meta->manifests = strdup("manifests");
meta->manifests = strdup("packagesite.yaml");
meta->digests = strdup("digests");
/* Not using fulldb */
meta->fulldb = NULL;
Expand Down
10 changes: 5 additions & 5 deletions libpkg/pkg_repo_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,18 @@ pkg_repo_update_incremental(const char *name, struct pkg_repo *repo, time_t *mti
pkg_repo_update_increment_item_new(&ldel, origin, digest, 4, 0);
}


if (pkg_repo_fetch_meta(repo, NULL) == EPKG_FATAL)
pkg_emit_notice("repository %s has no meta file, use default settings",
repo->name);

fdigests = pkg_repo_fetch_remote_extract_tmp(repo,
repo_digests_archive, "txz", &local_t,
&rc, repo_digests_file);
repo->meta->digests, &local_t, &rc);
if (fdigests == NULL)
goto cleanup;
digest_t = local_t;
local_t = *mtime;
fmanifest = pkg_repo_fetch_remote_extract_tmp(repo,
repo_packagesite_archive, "txz", &local_t,
&rc, repo_packagesite_file);
repo->meta->manifests, &local_t, &rc);
if (fmanifest == NULL)
goto cleanup;
packagesite_t = digest_t;
Expand Down
8 changes: 5 additions & 3 deletions libpkg/private/pkg.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,12 @@ int pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags);
#define PKG_DELETE_NOSCRIPT (1<<2)
#define PKG_DELETE_CONFLICT (1<<3)

int pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest, time_t *t);
int pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url,
int dest, time_t *t);
int pkg_repo_fetch_package(struct pkg *pkg);
FILE * pkg_repo_fetch_remote_extract_tmp(struct pkg_repo *repo, const char *filename,
const char *extension, time_t *t, int *rc, const char *archive_file);
FILE* pkg_repo_fetch_remote_extract_tmp(struct pkg_repo *repo,
const char *filename, time_t *t, int *rc);
int pkg_repo_fetch_meta(struct pkg_repo *repo, time_t *t);

struct pkg_repo_meta *pkg_repo_meta_default(void);
int pkg_repo_meta_load(const char *file, struct pkg_repo_meta **target);
Expand Down

0 comments on commit f710369

Please sign in to comment.