kpm: check package cache before downloading
git-svn-id: svn://kolibrios.org@5727 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
f73d56b77c
commit
764d8dd3a3
@ -1,5 +1,6 @@
|
||||
#include "tinyxml/tinyxml.h"
|
||||
#include "collection.h"
|
||||
#include <sys/kos_io.h>
|
||||
|
||||
const char *key_collection = "collection";
|
||||
const char *key_package = "package";
|
||||
@ -70,4 +71,56 @@ collection_t* load_collection_file(const char *name)
|
||||
return collection;
|
||||
}
|
||||
|
||||
int build_install_list(list_t *list, collection_t *collection)
|
||||
{
|
||||
pkg_group_t *gr;
|
||||
int count = 0;
|
||||
|
||||
list_for_each_entry(gr, &collection->groups, list)
|
||||
{
|
||||
package_t *pkg, *tmp;
|
||||
|
||||
list_for_each_entry(tmp, &gr->packages, list)
|
||||
{
|
||||
pkg = (package_t*)malloc(sizeof(package_t));
|
||||
|
||||
pkg->id = tmp->id;
|
||||
pkg->name = strdup(tmp->name);
|
||||
pkg->version = strdup(tmp->version);
|
||||
pkg->filename = strdup(tmp->filename);
|
||||
pkg->description = strdup(tmp->description);
|
||||
list_add_tail(&pkg->list, list);
|
||||
// printf("add package %s-%s\n", pkg->name, pkg->version);
|
||||
|
||||
count++;
|
||||
}
|
||||
};
|
||||
return count;
|
||||
}
|
||||
|
||||
int build_download_list(list_t *download, list_t *src)
|
||||
{
|
||||
int count = 0;
|
||||
char *cache_path;
|
||||
package_t *pkg, *tmp;
|
||||
fileinfo_t info;
|
||||
list_for_each_entry(tmp, src, list)
|
||||
{
|
||||
cache_path = make_cache_path(tmp->filename);
|
||||
|
||||
if( get_fileinfo(cache_path, &info) != 0)
|
||||
{
|
||||
pkg = (package_t*)malloc(sizeof(package_t));
|
||||
|
||||
pkg->id = tmp->id;
|
||||
pkg->name = strdup(tmp->name);
|
||||
pkg->version = strdup(tmp->version);
|
||||
pkg->filename = strdup(tmp->filename);
|
||||
pkg->description = strdup(tmp->description);
|
||||
list_add_tail(&pkg->list, download);
|
||||
count++;
|
||||
printf("add package %s-%s\n", pkg->name, pkg->version);
|
||||
};
|
||||
}
|
||||
return count;
|
||||
};
|
||||
|
@ -32,6 +32,10 @@ typedef struct package
|
||||
collection_t* load_collection_file(const char *name);
|
||||
collection_t* load_collection_buffer(const char *buffer);
|
||||
|
||||
int build_install_list(list_t *list, collection_t *collection);
|
||||
int build_download_list(list_t *download, list_t *src);
|
||||
char *make_cache_path(const char *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -17,13 +17,20 @@ char *make_url(const char *name)
|
||||
return url_buf;
|
||||
};
|
||||
|
||||
char *make_cache_path(const char *path)
|
||||
char *make_tmp_path(const char *path)
|
||||
{
|
||||
static char path_buf[64] = "/tmp0/1/";
|
||||
strcpy(&path_buf[8], path);
|
||||
return path_buf;
|
||||
};
|
||||
|
||||
char *make_cache_path(const char *path)
|
||||
{
|
||||
static char path_buf[64] = "/kolibrios/kpm/cache/";
|
||||
strcpy(&path_buf[21], path);
|
||||
return path_buf;
|
||||
};
|
||||
|
||||
int http_load_file(const char *path, const char *url)
|
||||
{
|
||||
http_t *http;
|
||||
@ -63,7 +70,7 @@ int http_load_file(const char *path, const char *url)
|
||||
{
|
||||
memcpy(buf+offset, http->content_ptr, count);
|
||||
offset+= count;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tail = count+offset-BUFFSIZE;
|
||||
@ -114,32 +121,36 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int count;
|
||||
char *cache_path;
|
||||
char *tmp_path;
|
||||
|
||||
if(http_init())
|
||||
goto err_init;
|
||||
|
||||
cache_path = make_cache_path("packages.xml");
|
||||
tmp_path = make_tmp_path("packages.xml");
|
||||
|
||||
count = http_load_file(cache_path, make_url("packages.xml"));
|
||||
count = http_load_file(tmp_path, make_url("packages.xml"));
|
||||
|
||||
if(count)
|
||||
{
|
||||
collection_t *collection;
|
||||
pkg_group_t *gr;
|
||||
package_t *pkg;
|
||||
LIST_HEAD(install_list);
|
||||
LIST_HEAD(download_list);
|
||||
|
||||
collection = load_collection_file(cache_path);
|
||||
collection = load_collection_file(tmp_path);
|
||||
|
||||
list_for_each_entry(gr, &collection->groups, list)
|
||||
if(collection && build_install_list(&install_list, collection))
|
||||
{
|
||||
package_t *pkg;
|
||||
|
||||
list_for_each_entry(pkg, &gr->packages, list)
|
||||
if(build_download_list(&download_list, &install_list))
|
||||
{
|
||||
printf("package %s-%s\n", pkg->name, pkg->version);
|
||||
cache_path = make_cache_path(pkg->filename);
|
||||
count = http_load_file(cache_path, make_url(pkg->filename));
|
||||
printf("%s loaded %d\n",cache_path, count);
|
||||
}
|
||||
list_for_each_entry(pkg, &download_list, list)
|
||||
{
|
||||
printf("package %s-%s\n", pkg->name, pkg->version);
|
||||
cache_path = make_cache_path(pkg->filename);
|
||||
count = http_load_file(cache_path, make_url(pkg->filename));
|
||||
printf("%s loaded %d bytes\n",cache_path, count);
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user