mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 07:48:50 -05:00
Report local file URL for -Sp operations if package is in cache
When using "pacman -Sp" operation to get URLs of packages to download, it is useful to know which packages are already in the file cache and do not need downloaded. Print packages in the cache with a file:// prefix. e.g $ pacman -Sp glibc file:///var/cache/pacman/glibc-2.23-1-x86_64.pkg.tar.xz Also use package locations in case statements rather than opersations. This allows the ALPM_PKG_SYNCDB to fall thorough to just printing the package name for weird serverless repo setups. Fixes FS#15868 Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
02a0bf550a
commit
7bebe4deff
@ -1025,16 +1025,37 @@ static char *pkg_get_location(alpm_pkg_t *pkg)
|
||||
{
|
||||
alpm_list_t *servers;
|
||||
char *string = NULL;
|
||||
switch(config->op) {
|
||||
case PM_OP_SYNC:
|
||||
switch(alpm_pkg_get_origin(pkg)) {
|
||||
case ALPM_PKG_FROM_SYNCDB:
|
||||
if(alpm_pkg_download_size(pkg) == 0) {
|
||||
/* file is already in the package cache */
|
||||
alpm_list_t *i;
|
||||
const char *pkgfile = alpm_pkg_get_filename(pkg);
|
||||
char path[PATH_MAX];
|
||||
struct stat buf;
|
||||
|
||||
for(i = alpm_option_get_cachedirs(config->handle); i; i = i->next) {
|
||||
snprintf(path, PATH_MAX, "%s%s", (char *)i->data, pkgfile);
|
||||
if(stat(path, &buf) == 0 && S_ISREG(buf.st_mode)) {
|
||||
pm_asprintf(&string, "file://%s", path);
|
||||
return string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
servers = alpm_db_get_servers(alpm_pkg_get_db(pkg));
|
||||
if(servers) {
|
||||
pm_asprintf(&string, "%s/%s", (char *)(servers->data),
|
||||
alpm_pkg_get_filename(pkg));
|
||||
return string;
|
||||
}
|
||||
case PM_OP_UPGRADE:
|
||||
|
||||
/* fallthrough - for theoretical serverless repos */
|
||||
|
||||
case ALPM_PKG_FROM_FILE:
|
||||
return strdup(alpm_pkg_get_filename(pkg));
|
||||
|
||||
case ALPM_PKG_FROM_LOCALDB:
|
||||
default:
|
||||
pm_asprintf(&string, "%s-%s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
|
||||
return string;
|
||||
|
Loading…
Reference in New Issue
Block a user