xbps-repo: changed the 'sync' target to update from all registered

remote repositories, so remove its argument.

xbps_sync_repository_pkg_index:
 - create the local repo dir in XBPS_META_PATH.
 - also add the uri scheme (http://, https://, ftp://) in the created
   local directory and subst ':' also with an underscore.
 - do not create local repo directories unless the download pkg-index
   plist file is verified to be fetched correctly.

xbps_check_is_repo_string_remote:
  New function to check if a repo string is a remote repository, use
  it in all places where it was used before.

--HG--
extra : convert_revision : xtraeme%40gmail.com-20091123042316-rmu4w3ehoxwh3iz8
This commit is contained in:
Juan RP
2009-11-23 04:23:16 +00:00
parent a95aecaf70
commit 13706cf0a5
6 changed files with 169 additions and 63 deletions

View File

@@ -45,23 +45,23 @@ xbps_get_remote_repo_string(const char *uri)
return NULL;
/*
* Replace dots and slashes with underscores, so that
* Replace '.' ':' and '/' characters with underscores, so that
* provided URL:
*
* www.foo.org/blah/xbps/binpkg-repo
* http://www.foo.org/blah/xbps/binpkg-repo
*
* becomes:
*
* www_foo_org_blah_xbps_binpkg_repo
* http___www_foo_org_blah_xbps_binpkg_repo
*
*/
p = xbps_xasprintf("%s%s", url->host, url->doc);
p = xbps_xasprintf("%s://%s%s", url->scheme, url->host, url->doc);
fetchFreeURL(url);
if (p == NULL)
return NULL;
for (i = 0; i < strlen(p); i++) {
if (p[i] == '.' || p[i] == '/')
if (p[i] == '.' || p[i] == '/' || p[i] == ':')
p[i] = '_';
}
@@ -71,10 +71,17 @@ xbps_get_remote_repo_string(const char *uri)
int SYMEXPORT
xbps_sync_repository_pkg_index(const char *uri)
{
struct url *url;
struct url *url = NULL;
struct utsname un;
char *rpidx, *dir, *lrepodir, *uri_fixedp = NULL;
struct stat st;
const char *fetch_outputdir;
char *rpidx, *dir, *lrepodir, *uri_fixedp;
char *metadir, *tmp_metafile, *lrepofile;
int rv = 0;
bool only_sync = false;
rpidx = dir = lrepodir = uri_fixedp = NULL;
metadir = tmp_metafile = lrepofile = NULL;
if (uname(&un) == -1)
return errno;
@@ -88,55 +95,137 @@ xbps_sync_repository_pkg_index(const char *uri)
return errno;
}
/*
* Create metadir if it doesn't exist yet.
*/
metadir = xbps_xasprintf("%s/%s", xbps_get_rootdir(),
XBPS_META_PATH);
if (metadir == NULL) {
rv = errno;
goto out;
}
rv = stat(metadir, &st);
if (rv == -1 && errno == ENOENT) {
if (mkpath(metadir, 0755) == -1) {
rv = errno;
goto out;
}
} else if (rv == 0 && !S_ISDIR(st.st_mode)) {
rv = ENOTDIR;
goto out;
}
/*
* Remote repository pkg-index.plist full URL.
*/
rpidx = xbps_xasprintf("%s/%s/%s", uri, un.machine, XBPS_PKGINDEX);
if (rpidx == NULL) {
rv = errno;
goto out;
}
/*
* Save temporary file in XBPS_META_PATH, and rename if it
* was downloaded successfully.
*/
tmp_metafile = xbps_xasprintf("%s/%s", metadir, XBPS_PKGINDEX);
if (tmp_metafile == NULL) {
rv = errno;
goto out;
}
/*
* Full path to machine arch local repository directory.
*/
lrepodir = xbps_xasprintf("%s/%s/%s/%s",
xbps_get_rootdir(), XBPS_META_PATH, uri_fixedp, un.machine);
if (lrepodir == NULL) {
rv = errno;
goto out;
}
/*
* If directory exists probably the pkg-index.plist file
* was downloaded previously...
*/
rv = stat(lrepodir, &st);
if (rv == 0 && S_ISDIR(st.st_mode)) {
only_sync = true;
fetch_outputdir = lrepodir;
} else
fetch_outputdir = metadir;
/*
* Download pkg-index.plist file from repository.
*/
if ((rv = xbps_fetch_file(rpidx, fetch_outputdir,
true, NULL)) != 0) {
(void)remove(tmp_metafile);
goto out;
}
if (only_sync)
goto out;
/*
* Create local arch repodir:
*
* <rootdir>/var/db/xbps/repo/<url_path_blah>/<arch>
*/
lrepodir = xbps_xasprintf("%s/%s/repo/%s/%s",
xbps_get_rootdir(), XBPS_META_PATH, uri_fixedp, un.machine);
if (lrepodir == NULL) {
fetchFreeURL(url);
free(uri_fixedp);
return errno;
}
if (mkpath(lrepodir, 0755) == -1) {
free(lrepodir);
free(uri_fixedp);
fetchFreeURL(url);
return errno;
rv = stat(lrepodir, &st);
if (rv == -1 && errno == ENOENT) {
if (mkpath(lrepodir, 0755) == -1) {
rv = errno;
goto out;
}
} else if (rv == 0 && !S_ISDIR(st.st_mode)) {
rv = ENOTDIR;
goto out;
}
/*
* Create local noarch repodir:
*
* <rootdir>/var/db/xbps/repo/<url_path_blah>/noarch
*/
dir = xbps_xasprintf("%s/%s/repo/%s/noarch",
dir = xbps_xasprintf("%s/%s/%s/noarch",
xbps_get_rootdir(), XBPS_META_PATH, uri_fixedp);
free(uri_fixedp);
fetchFreeURL(url);
if (dir == NULL) {
free(lrepodir);
return errno;
rv = errno;
goto out;
}
if (mkpath(dir, 0755) == -1) {
rv = stat(dir, &st);
if (rv == -1 && errno == ENOENT) {
if (mkpath(dir, 0755) == -1) {
free(dir);
rv = errno;
goto out;
}
} else if (rv == 0 && !S_ISDIR(st.st_mode)) {
free(dir);
free(lrepodir);
return errno;
rv = ENOTDIR;
goto out;
}
free(dir);
/*
* Download pkg-index.plist file from repository.
*/
rpidx = xbps_xasprintf("%s/%s/%s", uri, un.machine, XBPS_PKGINDEX);
if (rpidx == NULL) {
free(lrepodir);
return errno;
lrepofile = xbps_xasprintf("%s/%s", lrepodir, XBPS_PKGINDEX);
if (lrepofile == NULL) {
rv = errno;
goto out;
}
rv = xbps_fetch_file(rpidx, lrepodir, true, NULL);
free(rpidx);
free(lrepodir);
/*
* Rename to destination file now it has been fetched successfully.
*/
rv = rename(tmp_metafile, lrepofile);
out:
if (rpidx)
free(rpidx);
if (lrepodir)
free(lrepodir);
if (metadir)
free(metadir);
if (tmp_metafile)
free(tmp_metafile);
if (lrepofile)
free(lrepofile);
if (url)
fetchFreeURL(url);
if (uri_fixedp)
free(uri_fixedp);
return rv;
}

View File

@@ -111,6 +111,19 @@ xbps_check_pkg_file_hash(prop_dictionary_t pkgd, const char *repoloc)
return rv;
}
bool SYMEXPORT
xbps_check_is_repo_string_remote(const char *uri)
{
assert(uri != NULL);
if ((strncmp(uri, "https://", 8) == 0) ||
(strncmp(uri, "http://", 7) == 0) ||
(strncmp(uri, "ftp://", 6) == 0))
return true;
return false;
}
int SYMEXPORT
xbps_check_is_installed_pkg(const char *pkg)
{
@@ -289,7 +302,7 @@ get_pkg_index_remote_plist(const char *uri, const char *machine)
if (uri_fixed == NULL)
return NULL;
repodir = xbps_xasprintf("%s/%s/repo/%s/%s/%s",
repodir = xbps_xasprintf("%s/%s/%s/%s/%s",
xbps_get_rootdir(), XBPS_META_PATH, uri_fixed,
machine, XBPS_PKGINDEX);
if (repodir == NULL) {