static int do_unlock(struct pkgdb *db, struct pkg *pkg) { if (!pkg_is_locked(pkg)) { if (!quiet) pkg_printf("%n-%v: already unlocked\n", pkg, pkg); return (EPKG_OK); } if (!query_yesno(false, "%n-%v: unlock this package? [y/N]: ", pkg, pkg)) return (EPKG_OK); if (!quiet) pkg_printf("Unlocking %n-%v\n", pkg, pkg); return (pkgdb_set(db, pkg, PKG_SET_LOCKED, (int64_t)false)); }
/** * Check whether a package is in the universe already or add it * @return item or NULL */ int pkg_jobs_universe_add_pkg(struct pkg_jobs_universe *universe, struct pkg *pkg, bool force, struct pkg_job_universe_item **found) { struct pkg_job_universe_item *item, *seen, *tmp = NULL; pkg_validate(pkg, universe->j->db); if (pkg->digest == NULL) { pkg_debug(3, "no digest found for package %s (%s-%s)", pkg->uid, pkg->name, pkg->version); if (pkg_checksum_calculate(pkg, universe->j->db) != EPKG_OK) { *found = NULL; return (EPKG_FATAL); } } kh_find(pkg_jobs_seen, universe->seen, pkg->digest, seen); if (seen) { bool same_package = false; DL_FOREACH(seen, tmp) { if (tmp->pkg == pkg || (tmp->pkg->type == pkg->type && strcmp(tmp->pkg->digest, pkg->digest) == 0)) { if (tmp->pkg->reponame != NULL) { if (strcmp(tmp->pkg->reponame, pkg->reponame) == 0) { same_package = true; break; } } else { same_package = true; break; } } } if (same_package) { if (found != NULL) { *found = seen; } return (EPKG_END); } } if (pkg_is_locked(pkg)) { pkg_emit_locked(pkg); return (EPKG_LOCKED); } pkg_debug(2, "universe: add new %s pkg: %s, (%s-%s:%s)", (pkg->type == PKG_INSTALLED ? "local" : "remote"), pkg->uid, pkg->name, pkg->version, pkg->digest); item = calloc(1, sizeof (struct pkg_job_universe_item)); if (item == NULL) { pkg_emit_errno("pkg_jobs_pkg_insert_universe", "calloc: struct pkg_job_universe_item"); return (EPKG_FATAL); } item->pkg = pkg; HASH_FIND_STR(universe->items, pkg->uid, tmp); if (tmp == NULL) HASH_ADD_KEYPTR(hh, universe->items, pkg->uid, strlen(pkg->uid), item); DL_APPEND(tmp, item); if (seen == NULL) kh_safe_add(pkg_jobs_seen, universe->seen, item, item->pkg->digest); universe->nitems++; if (found != NULL) *found = item; return (EPKG_OK); }
void print_jobs_summary(struct pkg_jobs *jobs, const char *msg, ...) { struct pkg *pkg = NULL; char path[MAXPATHLEN]; struct stat st; const char *oldversion, *cachedir, *why; int64_t dlsize, oldsize, newsize; int64_t flatsize, oldflatsize, pkgsize; char size[7]; va_list ap; pkg_jobs_t type; type = pkg_jobs_type(jobs); va_start(ap, msg); vprintf(msg, ap); va_end(ap); dlsize = oldsize = newsize = 0; flatsize = oldflatsize = pkgsize = 0; oldversion = NULL; pkg_config_string(PKG_CONFIG_CACHEDIR, &cachedir); while (pkg_jobs(jobs, &pkg) == EPKG_OK) { pkg_get(pkg, PKG_OLD_VERSION, &oldversion, PKG_FLATSIZE, &flatsize, PKG_OLD_FLATSIZE, &oldflatsize, PKG_PKGSIZE, &pkgsize, PKG_REASON, &why); if (pkg_is_locked(pkg)) { pkg_printf("\tPackage %n-%v is locked ", pkg, pkg); switch (type) { case PKG_JOBS_INSTALL: case PKG_JOBS_UPGRADE: /* If it's a new install, then it * cannot have been locked yet. */ if (oldversion != NULL) { switch(pkg_version_change(pkg)) { case PKG_UPGRADE: pkg_printf("and may not be upgraded to version %v\n", pkg); break; case PKG_REINSTALL: printf("and may not be reinstalled\n"); break; case PKG_DOWNGRADE: pkg_printf("and may not be downgraded to version %v\n", pkg); break; } continue; } break; case PKG_JOBS_DEINSTALL: case PKG_JOBS_AUTOREMOVE: printf("and may not be deinstalled\n"); continue; break; case PKG_JOBS_FETCH: printf("but a new package can still be fetched\n"); break; } } switch (type) { case PKG_JOBS_INSTALL: case PKG_JOBS_UPGRADE: pkg_snprintf(path, MAXPATHLEN, "%S/%R", cachedir, pkg); if (stat(path, &st) == -1 || pkgsize != st.st_size) /* file looks corrupted (wrong size), assume a checksum mismatch will occur later and the file will be fetched from remote again */ dlsize += pkgsize; if (oldversion != NULL) { switch (pkg_version_change(pkg)) { case PKG_DOWNGRADE: pkg_printf("\tDowngrading %n: %V -> %v", pkg, pkg, pkg); if (pkg_repos_count() > 1) pkg_printf(" [%N]", pkg); printf("\n"); break; case PKG_REINSTALL: pkg_printf("\tReinstalling %n-%v", pkg, pkg); if (pkg_repos_count() > 1) pkg_printf(" [%N]", pkg); if (why != NULL) printf(" (%s)", why); printf("\n"); break; case PKG_UPGRADE: pkg_printf("\tUpgrading %n: %V -> %v", pkg, pkg, pkg); if (pkg_repos_count() > 1) pkg_printf(" [%N]", pkg); printf("\n"); break; } oldsize += oldflatsize; newsize += flatsize; } else { newsize += flatsize; pkg_printf("\tInstalling %n: %v", pkg, pkg); if (pkg_repos_count() > 1) pkg_printf(" [%N]", pkg); printf("\n"); } break; case PKG_JOBS_DEINSTALL: case PKG_JOBS_AUTOREMOVE: oldsize += oldflatsize; newsize += flatsize; pkg_printf("\t%n-%v\n", pkg, pkg); break; case PKG_JOBS_FETCH: dlsize += pkgsize; pkg_snprintf(path, MAXPATHLEN, "%S/%R", cachedir, pkg); if (stat(path, &st) != -1) oldsize = st.st_size; else oldsize = 0; dlsize -= oldsize; humanize_number(size, sizeof(size), pkgsize, "B", HN_AUTOSCALE, 0); pkg_printf("\t%n-%v ", pkg, pkg); printf("(%" PRId64 "%% of %s)\n", 100 - (100 * oldsize)/pkgsize, size); break; } } if (oldsize > newsize) { humanize_number(size, sizeof(size), oldsize - newsize, "B", HN_AUTOSCALE, 0); switch (type) { case PKG_JOBS_INSTALL: printf("\nThe installation will free %s\n", size); break; case PKG_JOBS_UPGRADE: printf("\nThe upgrade will free %s\n", size); break; case PKG_JOBS_DEINSTALL: case PKG_JOBS_AUTOREMOVE: printf("\nThe deinstallation will free %s\n", size); break; case PKG_JOBS_FETCH: /* nothing to report here */ break; } } else if (newsize > oldsize) { humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0); switch (type) { case PKG_JOBS_INSTALL: printf("\nThe installation will require %s more space\n", size); break; case PKG_JOBS_UPGRADE: printf("\nThe upgrade will require %s more space\n", size); break; case PKG_JOBS_DEINSTALL: case PKG_JOBS_AUTOREMOVE: printf("\nThe deinstallation will require %s more space\n", size); break; case PKG_JOBS_FETCH: /* nothing to report here */ break; } } if ((type == PKG_JOBS_INSTALL) || (type == PKG_JOBS_FETCH) || (type == PKG_JOBS_UPGRADE)) { humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0); printf("\n%s to be downloaded\n", size); } }
int pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags) { struct pkg_dep *rdep = NULL; int ret; bool handle_rc = false; const char *origin; assert(pkg != NULL); assert(db != NULL); /* * Do not trust the existing entries as it may have changed if we * delete packages in batch. */ pkg_list_free(pkg, PKG_RDEPS); /* * Ensure that we have all the informations we need */ if ((ret = pkgdb_load_rdeps(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_load_files(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_load_dirs(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_load_scripts(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_load_mtree(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_load_annotations(db, pkg)) != EPKG_OK) return (ret); if ((flags & PKG_DELETE_UPGRADE) == 0) pkg_emit_deinstall_begin(pkg); /* If the package is locked */ if (pkg_is_locked(pkg)) { pkg_emit_locked(pkg); return (EPKG_LOCKED); } /* If there are dependencies */ if ((flags & (PKG_DELETE_UPGRADE|PKG_DELETE_CONFLICT)) == 0) { if (pkg_rdeps(pkg, &rdep) == EPKG_OK) { pkg_emit_required(pkg, flags & PKG_DELETE_FORCE); if ((flags & PKG_DELETE_FORCE) == 0) return (EPKG_REQUIRED); } } /* * stop the different related services if the users do want that * and that the service is running */ handle_rc = pkg_object_bool(pkg_config_get("HANDLE_RC_SCRIPTS")); if (handle_rc) pkg_start_stop_rc_scripts(pkg, PKG_RC_STOP); if ((flags & PKG_DELETE_NOSCRIPT) == 0) { if (flags & PKG_DELETE_UPGRADE) { ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_UPGRADE); if (ret != EPKG_OK) return (ret); } else { ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_DEINSTALL); if (ret != EPKG_OK) return (ret); } } if ((ret = pkg_delete_files(pkg, flags & PKG_DELETE_FORCE ? 1 : 0)) != EPKG_OK) return (ret); if ((flags & (PKG_DELETE_NOSCRIPT | PKG_DELETE_UPGRADE)) == 0) { ret = pkg_script_run(pkg, PKG_SCRIPT_POST_DEINSTALL); if (ret != EPKG_OK) return (ret); } ret = pkg_delete_dirs(db, pkg, flags & PKG_DELETE_FORCE); if (ret != EPKG_OK) return (ret); if ((flags & PKG_DELETE_UPGRADE) == 0) pkg_emit_deinstall_finished(pkg); pkg_get(pkg, PKG_ORIGIN, &origin); return (pkgdb_unregister_pkg(db, origin)); }
int pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags) { int ret; bool handle_rc = false; int64_t id; const unsigned load_flags = PKG_LOAD_RDEPS|PKG_LOAD_FILES|PKG_LOAD_DIRS| PKG_LOAD_SCRIPTS|PKG_LOAD_MTREE|PKG_LOAD_ANNOTATIONS; assert(pkg != NULL); assert(db != NULL); if (pkgdb_ensure_loaded(db, pkg, load_flags) != EPKG_OK) return (EPKG_FATAL); if ((flags & PKG_DELETE_UPGRADE) == 0) pkg_emit_deinstall_begin(pkg); /* If the package is locked */ if (pkg_is_locked(pkg)) { pkg_emit_locked(pkg); return (EPKG_LOCKED); } /* * stop the different related services if the users do want that * and that the service is running */ handle_rc = pkg_object_bool(pkg_config_get("HANDLE_RC_SCRIPTS")); if (handle_rc) pkg_start_stop_rc_scripts(pkg, PKG_RC_STOP); if ((flags & PKG_DELETE_NOSCRIPT) == 0) { if (flags & PKG_DELETE_UPGRADE) { ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_UPGRADE); if (ret != EPKG_OK) return (ret); } else { ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_DEINSTALL); if (ret != EPKG_OK) return (ret); } } if ((ret = pkg_delete_files(pkg, flags & PKG_DELETE_FORCE ? 1 : 0)) != EPKG_OK) return (ret); if ((flags & (PKG_DELETE_NOSCRIPT | PKG_DELETE_UPGRADE)) == 0) { ret = pkg_script_run(pkg, PKG_SCRIPT_POST_DEINSTALL); if (ret != EPKG_OK) return (ret); } ret = pkg_delete_dirs(db, pkg); if (ret != EPKG_OK) return (ret); if ((flags & PKG_DELETE_UPGRADE) == 0) pkg_emit_deinstall_finished(pkg); pkg_get(pkg, PKG_ROWID, &id); return (pkgdb_unregister_pkg(db, id)); }
static void print_jobs_summary_pkg(struct pkg *pkg, pkg_jobs_t type, int64_t *oldsize, int64_t *newsize, int64_t *dlsize) { const char *oldversion, *cachedir, *why; char path[MAXPATHLEN]; struct stat st; int64_t flatsize, oldflatsize, pkgsize; char size[7]; flatsize = oldflatsize = pkgsize = 0; oldversion = NULL; pkg_config_string(PKG_CONFIG_CACHEDIR, &cachedir); pkg_get(pkg, PKG_OLD_VERSION, &oldversion, PKG_FLATSIZE, &flatsize, PKG_OLD_FLATSIZE, &oldflatsize, PKG_PKGSIZE, &pkgsize, PKG_REASON, &why); if (pkg_is_locked(pkg)) { pkg_printf("\tPackage %n-%v is locked ", pkg, pkg); switch (type) { case PKG_JOBS_INSTALL: case PKG_JOBS_UPGRADE: /* If it's a new install, then it * cannot have been locked yet. */ if (oldversion != NULL) { switch(pkg_version_change(pkg)) { case PKG_UPGRADE: pkg_printf("and may not be upgraded to version %v\n", pkg); break; case PKG_REINSTALL: printf("and may not be reinstalled\n"); break; case PKG_DOWNGRADE: pkg_printf("and may not be downgraded to version %v\n", pkg); break; } return; } break; case PKG_JOBS_DEINSTALL: case PKG_JOBS_AUTOREMOVE: printf("and may not be deinstalled\n"); return; break; case PKG_JOBS_FETCH: printf("but a new package can still be fetched\n"); break; } } switch (type) { case PKG_JOBS_INSTALL: case PKG_JOBS_UPGRADE: pkg_snprintf(path, MAXPATHLEN, "%S/%R", cachedir, pkg); if (stat(path, &st) == -1 || pkgsize != st.st_size) /* file looks corrupted (wrong size), assume a checksum mismatch will occur later and the file will be fetched from remote again */ *dlsize += pkgsize; if (oldversion != NULL) { switch (pkg_version_change(pkg)) { case PKG_DOWNGRADE: pkg_printf("\tDowngrading %n: %V -> %v", pkg, pkg, pkg); if (pkg_repos_total_count() > 1) pkg_printf(" [%N]", pkg); printf("\n"); break; case PKG_REINSTALL: pkg_printf("\tReinstalling %n-%v", pkg, pkg); if (pkg_repos_total_count() > 1) pkg_printf(" [%N]", pkg); if (why != NULL) printf(" (%s)", why); printf("\n"); break; case PKG_UPGRADE: pkg_printf("\tUpgrading %n: %V -> %v", pkg, pkg, pkg); if (pkg_repos_total_count() > 1) pkg_printf(" [%N]", pkg); printf("\n"); break; } *oldsize += oldflatsize; *newsize += flatsize; } else { *newsize += flatsize; pkg_printf("\tInstalling %n: %v", pkg, pkg); if (pkg_repos_total_count() > 1) pkg_printf(" [%N]", pkg); printf("\n"); } break; case PKG_JOBS_DEINSTALL: case PKG_JOBS_AUTOREMOVE: *oldsize += oldflatsize; *newsize += flatsize; pkg_printf("\tRemoving %n-%v\n", pkg, pkg); break; case PKG_JOBS_FETCH: *dlsize += pkgsize; pkg_snprintf(path, MAXPATHLEN, "%S/%R", cachedir, pkg); if (stat(path, &st) != -1) *oldsize = st.st_size; else *oldsize = 0; *dlsize -= *oldsize; humanize_number(size, sizeof(size), pkgsize, "B", HN_AUTOSCALE, 0); pkg_printf("\t%n-%v ", pkg, pkg); printf("(%" PRId64 "%% of %s)\n", 100 - (100 * (*oldsize))/pkgsize, size); break; } }