forked from mirrors/pacman
Compare commits
1 Commits
morganamil
...
morganamil
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a61c500557 |
@@ -364,6 +364,9 @@ Query Options (apply to '-Q')[[QO]]
|
||||
replacements are not checked here. This option works best if the sync
|
||||
database is refreshed using '-Sy'.
|
||||
|
||||
*-w, \--backup*::
|
||||
List all modified backup files owened by a given package. Multiple packages can
|
||||
be specified on the command line. Pass twice to print all backup files.
|
||||
|
||||
Remove Options (apply to '-R')[[RO]]
|
||||
------------------------------------
|
||||
|
||||
@@ -57,7 +57,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg)
|
||||
ASSERT(pkg->origin == ALPM_PKG_FROM_SYNCDB,
|
||||
RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1));
|
||||
|
||||
fpath = _alpm_cache_find_pkg(pkg, 0);
|
||||
fpath = _alpm_filecache_find(pkg->handle, pkg->filename);
|
||||
|
||||
retval = _alpm_test_checksum(fpath, pkg->md5sum, ALPM_PKG_VALIDATION_MD5SUM);
|
||||
|
||||
@@ -283,7 +283,7 @@ int SYMEXPORT alpm_pkg_get_sig(alpm_pkg_t *pkg, unsigned char **sig, size_t *sig
|
||||
alpm_errno_t err;
|
||||
int ret = -1;
|
||||
|
||||
pkgpath = _alpm_cache_find_pkg(pkg, 0);
|
||||
pkgpath = _alpm_filecache_find(pkg->handle, pkg->filename);
|
||||
if(!pkgpath) {
|
||||
GOTO_ERR(pkg->handle, ALPM_ERR_PKG_NOT_FOUND, cleanup);
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ static int compute_download_size(alpm_pkg_t *newpkg)
|
||||
|
||||
ASSERT(newpkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
|
||||
fname = newpkg->filename;
|
||||
fpath = _alpm_cache_find_pkg(newpkg, 0);
|
||||
fpath = _alpm_filecache_find(handle, fname);
|
||||
|
||||
/* downloaded file exists, so there's nothing to grab */
|
||||
if(fpath) {
|
||||
@@ -333,7 +333,7 @@ static int compute_download_size(alpm_pkg_t *newpkg)
|
||||
|
||||
CALLOC(fnamepart, strlen(fname) + 6, sizeof(char), return -1);
|
||||
sprintf(fnamepart, "%s.part", fname);
|
||||
fpath = _alpm_cache_find_pkg(newpkg, 1);
|
||||
fpath = _alpm_filecache_find(handle, fnamepart);
|
||||
if(fpath) {
|
||||
struct stat st;
|
||||
if(stat(fpath, &st) == 0) {
|
||||
@@ -737,13 +737,21 @@ static int find_dl_candidates(alpm_handle_t *handle, alpm_list_t **files)
|
||||
|
||||
ASSERT(spkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
|
||||
|
||||
need_download = spkg->download_size != 0 || !_alpm_cache_pkg_exists(spkg, 0);
|
||||
need_download = spkg->download_size != 0 || !_alpm_filecache_exists(handle, spkg->filename);
|
||||
/* even if the package file in the cache we need to check for
|
||||
* accompanion *.sig file as well.
|
||||
* If *.sig is not cached then force download the package + its signature file.
|
||||
*/
|
||||
if(!need_download && (siglevel & ALPM_SIG_PACKAGE)) {
|
||||
need_download = !_alpm_cache_pkg_exists(spkg, 1);
|
||||
char *sig_filename = NULL;
|
||||
int len = strlen(spkg->filename) + 5;
|
||||
|
||||
MALLOC(sig_filename, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
||||
snprintf(sig_filename, len, "%s.sig", spkg->filename);
|
||||
|
||||
need_download = !_alpm_filecache_exists(handle, sig_filename);
|
||||
|
||||
FREE(sig_filename);
|
||||
}
|
||||
|
||||
if(need_download) {
|
||||
@@ -982,7 +990,7 @@ static int check_validity(alpm_handle_t *handle,
|
||||
}
|
||||
|
||||
current_bytes += v.pkg->size;
|
||||
v.path = _alpm_cache_find_pkg(v.pkg, 0);
|
||||
v.path = _alpm_filecache_find(handle, v.pkg->filename);
|
||||
v.siglevel = alpm_db_get_siglevel(alpm_pkg_get_db(v.pkg));
|
||||
|
||||
if(_alpm_pkg_validate_internal(handle, v.path, v.pkg,
|
||||
@@ -1072,8 +1080,7 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data,
|
||||
}
|
||||
|
||||
current_bytes += spkg->size;
|
||||
|
||||
filepath = _alpm_cache_find_pkg(spkg, 0);
|
||||
filepath = _alpm_filecache_find(handle, spkg->filename);
|
||||
|
||||
/* load the package file and replace pkgcache entry with it in the target list */
|
||||
/* TODO: alpm_pkg_get_db() will not work on this target anymore */
|
||||
|
||||
@@ -815,37 +815,6 @@ int _alpm_str_cmp(const void *s1, const void *s2)
|
||||
return strcmp(s1, s2);
|
||||
}
|
||||
|
||||
char *_alpm_cache_find_pkg(alpm_pkg_t *pkg, int sig) {
|
||||
alpm_handle_t *handle = pkg->handle;
|
||||
struct stat buf;
|
||||
alpm_list_t *servers = pkg->origin_data.db->servers;
|
||||
char *retpath;
|
||||
char filepath[PATH_MAX];
|
||||
|
||||
for(alpm_list_t *j = servers; j; j = j->next) {
|
||||
char *server = j->data;
|
||||
|
||||
if(strncmp("file://", server, strlen("file://")) == 0) {
|
||||
int len = strlen(server) - strlen("file://") + 1 + strlen(pkg->filename) + 1;
|
||||
|
||||
if(sig) {
|
||||
len += strlen(".sig");
|
||||
snprintf(filepath, len, "%s/%s", server + strlen("file://"), pkg->filename);
|
||||
} else {
|
||||
snprintf(filepath, len, "%s/%s.sig", server + strlen("file://"), pkg->filename);
|
||||
}
|
||||
|
||||
if(stat(filepath, &buf) == 0 && S_ISREG(buf.st_mode)) {
|
||||
STRDUP(retpath, filepath, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
|
||||
_alpm_log(handle, ALPM_LOG_DEBUG, "found pkg in repo cache: %s\n", retpath);
|
||||
return retpath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _alpm_filecache_find(handle, pkg->filename);
|
||||
}
|
||||
|
||||
/** Find a filename in a registered alpm cachedir.
|
||||
* @param handle the context handle
|
||||
* @param filename name of file to find
|
||||
@@ -877,10 +846,10 @@ char *_alpm_filecache_find(alpm_handle_t *handle, const char *filename)
|
||||
* @param filename name of file to find
|
||||
* @return 0 if the filename was not found, 1 otherwise
|
||||
*/
|
||||
int _alpm_cache_pkg_exists(alpm_pkg_t *pkg, int sig)
|
||||
int _alpm_filecache_exists(alpm_handle_t *handle, const char *filename)
|
||||
{
|
||||
int res;
|
||||
char *fpath = _alpm_cache_find_pkg(pkg, sig);
|
||||
char *fpath = _alpm_filecache_find(handle, filename);
|
||||
res = (fpath != NULL);
|
||||
FREE(fpath);
|
||||
return res;
|
||||
|
||||
@@ -133,10 +133,9 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[],
|
||||
_alpm_cb_io in_cb, void *in_ctx);
|
||||
int _alpm_ldconfig(alpm_handle_t *handle);
|
||||
int _alpm_str_cmp(const void *s1, const void *s2);
|
||||
char *_alpm_cache_find_pkg(alpm_pkg_t *pkg, int sig);
|
||||
char *_alpm_filecache_find(alpm_handle_t *handle, const char *filename);
|
||||
/* Checks whether a file exists in cache */
|
||||
int _alpm_cache_pkg_exists(alpm_pkg_t *pkg, int sig);
|
||||
int _alpm_filecache_exists(alpm_handle_t *handle, const char *filename);
|
||||
const char *_alpm_filecache_setup(alpm_handle_t *handle);
|
||||
/* Unlike many uses of alpm_pkgvalidation_t, _alpm_test_checksum expects
|
||||
* an enum value rather than a bitfield. */
|
||||
|
||||
@@ -83,6 +83,7 @@ typedef struct __config_t {
|
||||
unsigned short op_q_upgrade;
|
||||
unsigned short op_q_check;
|
||||
unsigned short op_q_locality;
|
||||
unsigned short op_q_backup;
|
||||
|
||||
unsigned short op_s_clean;
|
||||
unsigned short op_s_downloadonly;
|
||||
@@ -180,6 +181,7 @@ enum {
|
||||
OP_DBPATH,
|
||||
OP_CASCADE,
|
||||
OP_CHANGELOG,
|
||||
OP_BACKUP,
|
||||
OP_CLEAN,
|
||||
OP_NODEPS,
|
||||
OP_DEPS,
|
||||
|
||||
@@ -348,7 +348,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
|
||||
|
||||
/* Print additional package info if info flag passed more than once */
|
||||
if(from == ALPM_PKG_FROM_LOCALDB && extra) {
|
||||
dump_pkg_backups(pkg);
|
||||
dump_backup_status(pkg);
|
||||
}
|
||||
|
||||
/* final newline to separate packages */
|
||||
@@ -359,6 +359,34 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
|
||||
alpm_list_free(validation);
|
||||
}
|
||||
|
||||
static int get_backup_file_changed(const char *root,
|
||||
const alpm_backup_t *backup)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
int ret = 0;
|
||||
|
||||
snprintf(path, PATH_MAX, "%s%s", root, backup->name);
|
||||
|
||||
/* if we find the file, calculate checksums, otherwise it is missing */
|
||||
if(access(path, R_OK) == 0) {
|
||||
char *md5sum = alpm_compute_md5sum(path);
|
||||
|
||||
if(md5sum == NULL) {
|
||||
pm_printf(ALPM_LOG_ERROR,
|
||||
_("could not calculate checksums for %s\n"), path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if checksums don't match, file has been modified */
|
||||
ret = strcmp(md5sum, backup->hash) != 0;
|
||||
free(md5sum);
|
||||
} else if(errno != ENOENT) {
|
||||
pm_printf(ALPM_LOG_ERROR,
|
||||
_("could not read %s: %s\n"), path, strerror(errno));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const char *get_backup_file_status(const char *root,
|
||||
const alpm_backup_t *backup)
|
||||
{
|
||||
@@ -401,7 +429,7 @@ static const char *get_backup_file_status(const char *root,
|
||||
|
||||
/* Display list of backup files and their modification states
|
||||
*/
|
||||
void dump_pkg_backups(alpm_pkg_t *pkg)
|
||||
void dump_backup_status(alpm_pkg_t *pkg)
|
||||
{
|
||||
alpm_list_t *i;
|
||||
const char *root = alpm_option_get_root(config->handle);
|
||||
@@ -450,6 +478,32 @@ void dump_pkg_files(alpm_pkg_t *pkg, int quiet)
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void dump_pkg_backups(alpm_pkg_t *pkg, int quiet, int all)
|
||||
{
|
||||
const char *pkgname, *root;
|
||||
alpm_list_t *backups;
|
||||
alpm_list_t *i;
|
||||
|
||||
pkgname = alpm_pkg_get_name(pkg);
|
||||
backups = alpm_pkg_get_backup(pkg);
|
||||
root = alpm_option_get_root(config->handle);
|
||||
|
||||
for(i = backups; i; i = i->next) {
|
||||
alpm_backup_t *backup = i->data;
|
||||
|
||||
if(!all && backup->hash && !get_backup_file_changed(root, backup)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!quiet) {
|
||||
printf("%s%s%s ", config->colstr.title, pkgname, config->colstr.nocolor);
|
||||
}
|
||||
printf("%s%s\n", root, backup->name);
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* Display the changelog of a package
|
||||
*/
|
||||
void dump_pkg_changelog(alpm_pkg_t *pkg)
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
|
||||
void dump_pkg_full(alpm_pkg_t *pkg, int extra);
|
||||
|
||||
void dump_pkg_backups(alpm_pkg_t *pkg);
|
||||
void dump_backup_status(alpm_pkg_t *pkg);
|
||||
void dump_pkg_backups(alpm_pkg_t *pkg, int quiet, int all);
|
||||
void dump_pkg_files(alpm_pkg_t *pkg, int quiet);
|
||||
void dump_pkg_changelog(alpm_pkg_t *pkg);
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ static void usage(int op, const char * const myname)
|
||||
addlist(_(" -t, --unrequired list packages not (optionally) required by any\n"
|
||||
" package (-tt to ignore optdepends) [filter]\n"));
|
||||
addlist(_(" -u, --upgrades list outdated packages [filter]\n"));
|
||||
addlist(_(" -w, --backup list modified backup files of a package (-xx for all backup files)\n"));
|
||||
} else if(op == PM_OP_SYNC) {
|
||||
printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg);
|
||||
printf("%s:\n", str_opt);
|
||||
@@ -516,6 +517,10 @@ static int parsearg_query(int opt)
|
||||
case 'c':
|
||||
config->op_q_changelog = 1;
|
||||
break;
|
||||
case OP_BACKUP:
|
||||
case 'w':
|
||||
(config->op_q_backup)++;
|
||||
break;
|
||||
case OP_DEPS:
|
||||
case 'd':
|
||||
config->op_q_deps = 1;
|
||||
@@ -583,6 +588,7 @@ static void checkargs_query_display_opts(const char *opname) {
|
||||
invalid_opt(config->op_q_check, opname, "--check");
|
||||
invalid_opt(config->op_q_info, opname, "--info");
|
||||
invalid_opt(config->op_q_list, opname, "--list");
|
||||
invalid_opt(config->op_q_backup, opname, "--backup");
|
||||
}
|
||||
|
||||
static void checkargs_query_filter_opts(const char *opname) {
|
||||
@@ -896,6 +902,7 @@ static int parseargs(int argc, char *argv[])
|
||||
{"dbpath", required_argument, 0, OP_DBPATH},
|
||||
{"cascade", no_argument, 0, OP_CASCADE},
|
||||
{"changelog", no_argument, 0, OP_CHANGELOG},
|
||||
{"backup", no_argument, 0, OP_BACKUP},
|
||||
{"clean", no_argument, 0, OP_CLEAN},
|
||||
{"nodeps", no_argument, 0, OP_NODEPS},
|
||||
{"deps", no_argument, 0, OP_DEPS},
|
||||
|
||||
@@ -315,6 +315,9 @@ static int display(alpm_pkg_t *pkg)
|
||||
if(config->op_q_list) {
|
||||
dump_pkg_files(pkg, config->quiet);
|
||||
}
|
||||
if(config->op_q_backup) {
|
||||
dump_pkg_backups(pkg, config->quiet, config->op_q_backup != 1);
|
||||
}
|
||||
if(config->op_q_changelog) {
|
||||
dump_pkg_changelog(pkg);
|
||||
}
|
||||
@@ -325,8 +328,8 @@ static int display(alpm_pkg_t *pkg)
|
||||
ret = check_pkg_full(pkg);
|
||||
}
|
||||
}
|
||||
if(!config->op_q_info && !config->op_q_list
|
||||
&& !config->op_q_changelog && !config->op_q_check) {
|
||||
if(!config->op_q_info && !config->op_q_list && !config->op_q_changelog
|
||||
&& !config->op_q_check && !config->op_q_backup) {
|
||||
if(!config->quiet) {
|
||||
const colstr_t *colstr = &config->colstr;
|
||||
printf("%s%s %s%s%s", colstr->title, alpm_pkg_get_name(pkg),
|
||||
@@ -431,7 +434,7 @@ int pacman_query(alpm_list_t *targets)
|
||||
db_local = alpm_get_localdb(config->handle);
|
||||
|
||||
/* operations on all packages in the local DB
|
||||
* valid: no-op (plain -Q), list, info, check
|
||||
* valid: no-op (plain -Q), list, info, check, backup
|
||||
* invalid: isfile, owns */
|
||||
if(targets == NULL) {
|
||||
if(config->op_q_isfile || config->op_q_owns) {
|
||||
|
||||
Reference in New Issue
Block a user