update: handle actual package updates outside of the library
This commit is contained in:
@ -8,9 +8,14 @@
|
||||
int main(int argc, char *argv[]) {
|
||||
lm_ctx_update_list_t *list = NULL;
|
||||
int ret = EXIT_FAILURE;
|
||||
lm_pkg_t pkg, *cur = NULL;
|
||||
lm_pkg_t pkg, *old = NULL, *new = NULL;
|
||||
lm_ctx_t ctx;
|
||||
|
||||
if (argc != 3) {
|
||||
printf("usage: %s <pool name> <pool url>\n", argv[0]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!mkdir_ifnot(ROOT_DIR)) {
|
||||
printf("failed to create root dir: %s\n", ROOT_DIR);
|
||||
return ret;
|
||||
@ -33,6 +38,14 @@ int main(int argc, char *argv[]) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (lm_ctx_pool_add(&ctx, argv[1], argv[2]) == NULL) {
|
||||
printf("failed to add pool: %s (%d)\n", lm_strerror(), lm_error());
|
||||
goto end;
|
||||
}
|
||||
|
||||
lm_ctx_ping(&ctx, NULL, NULL);
|
||||
lm_ctx_sync(&ctx, true, NULL, NULL);
|
||||
|
||||
if ((list = lm_ctx_update_list(&ctx)) == NULL) {
|
||||
printf("failed to get update list: %s (%d)", lm_strerror(), lm_error());
|
||||
goto end;
|
||||
@ -43,12 +56,28 @@ int main(int argc, char *argv[]) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
while ((cur = lm_ctx_update_list_next(list)) != NULL) {
|
||||
printf("updating %s (%s)...\n", cur->name, cur->version);
|
||||
if (!lm_ctx_update(&ctx, cur, NULL, NULL)) {
|
||||
while ((old = lm_ctx_update_list_next(list)) != NULL) {
|
||||
printf("updating %s (%s)...\n", old->name, old->version);
|
||||
|
||||
if ((new = lm_ctx_update(&ctx, old)) == NULL) {
|
||||
printf("failed to update package: %s\n", lm_strerror());
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!lm_ctx_download(&ctx, new, NULL, NULL)) {
|
||||
printf("failed to download new package: %s", lm_strerror());
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!lm_ctx_remove(&ctx, old, NULL, NULL)) {
|
||||
printf("failed to remove old package: %s", lm_strerror());
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!lm_ctx_install(&ctx, new, NULL, NULL)) {
|
||||
printf("failed to install new package: %s", lm_strerror());
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
|
@ -28,7 +28,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
lm_ctx_sync(&ctx, false, NULL, NULL);
|
||||
|
||||
if (!lm_ctx_serve(&ctx, argv[1], 10)) {
|
||||
if (!lm_ctx_serve(&ctx, argv[1], 10, NULL, NULL)) {
|
||||
printf("failed to serve the pools: %s (%d)\n", lm_strerror(), lm_error());
|
||||
goto end;
|
||||
}
|
||||
|
Reference in New Issue
Block a user