Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Ignore whitespace Rev 5726 → Rev 5727

/contrib/other/kpm/collection.cpp
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
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;
};
/contrib/other/kpm/collection.h
32,6 → 32,10
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
/contrib/other/kpm/kpm.c
17,7 → 17,7
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);
24,6 → 24,13
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
{
memcpy(buf+offset, http->content_ptr, count);
offset+= count;
else
@@ -116,32 +123,36 @@
{
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);
+ };
+ };
};
}