Merge branch 'backup-status'
This commit is contained in:
commit
d16a5ae7dd
1 changed files with 45 additions and 24 deletions
|
@ -25,6 +25,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
|
||||||
#include <alpm.h>
|
#include <alpm.h>
|
||||||
|
@ -157,6 +158,46 @@ void dump_pkg_sync(pmpkg_t *pkg, const char *treename, int level)
|
||||||
dump_pkg_full(pkg, -level);
|
dump_pkg_full(pkg, -level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *get_backup_file_status(const char *root,
|
||||||
|
const char *filename, const char *expected_md5)
|
||||||
|
{
|
||||||
|
char path[PATH_MAX];
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
snprintf(path, PATH_MAX, "%s%s", root, filename);
|
||||||
|
|
||||||
|
/* 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_fprintf(stderr, PM_LOG_ERROR,
|
||||||
|
_("could not calculate checksums for %s\n"), path);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if checksums don't match, file has been modified */
|
||||||
|
if (strcmp(md5sum, expected_md5) != 0) {
|
||||||
|
ret = "MODIFIED";
|
||||||
|
} else {
|
||||||
|
ret = "UNMODIFIED";
|
||||||
|
}
|
||||||
|
free(md5sum);
|
||||||
|
} else {
|
||||||
|
switch(errno) {
|
||||||
|
case EACCES:
|
||||||
|
ret = "UNREADABLE";
|
||||||
|
break;
|
||||||
|
case ENOENT:
|
||||||
|
ret = "MISSING";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret = "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
/* Display list of backup files and their modification states
|
/* Display list of backup files and their modification states
|
||||||
*/
|
*/
|
||||||
void dump_pkg_backups(pmpkg_t *pkg)
|
void dump_pkg_backups(pmpkg_t *pkg)
|
||||||
|
@ -167,37 +208,17 @@ void dump_pkg_backups(pmpkg_t *pkg)
|
||||||
if(alpm_pkg_get_backup(pkg)) {
|
if(alpm_pkg_get_backup(pkg)) {
|
||||||
/* package has backup files, so print them */
|
/* package has backup files, so print them */
|
||||||
for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) {
|
for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) {
|
||||||
char path[PATH_MAX];
|
const char *value;
|
||||||
char *str = strdup(alpm_list_getdata(i));
|
char *str = strdup(alpm_list_getdata(i));
|
||||||
char *ptr = index(str, '\t');
|
char *ptr = strchr(str, '\t');
|
||||||
if(ptr == NULL) {
|
if(ptr == NULL) {
|
||||||
free(str);
|
free(str);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
ptr++;
|
ptr++;
|
||||||
snprintf(path, PATH_MAX-1, "%s%s", root, str);
|
value = get_backup_file_status(root, str, ptr);
|
||||||
/* if we find the file, calculate checksums, otherwise it is missing */
|
printf("%s\t%s%s\n", value, root, str);
|
||||||
if(access(path, R_OK) == 0) {
|
|
||||||
char *md5sum = alpm_compute_md5sum(path);
|
|
||||||
|
|
||||||
if(md5sum == NULL) {
|
|
||||||
pm_fprintf(stderr, PM_LOG_ERROR,
|
|
||||||
_("could not calculate checksums for %s\n"), path);
|
|
||||||
free(str);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if checksums don't match, file has been modified */
|
|
||||||
if (strcmp(md5sum, ptr) != 0) {
|
|
||||||
printf(_("MODIFIED\t%s\n"), path);
|
|
||||||
} else {
|
|
||||||
printf(_("Not Modified\t%s\n"), path);
|
|
||||||
}
|
|
||||||
free(md5sum);
|
|
||||||
} else {
|
|
||||||
printf(_("MISSING\t\t%s\n"), path);
|
|
||||||
}
|
|
||||||
free(str);
|
free(str);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue