1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#include <limits.h>
#include <string.h>
#include <errno.h>
#include "check.h"
#include "conf.h"
#include "util.h"
static int check_file_exists(const char *pkgname, const char * filepath,
struct stat * st)
{
if(lstat(filepath, st) != 0) {
if(config->quiet) {
printf("%s %s\n", pkgname, filepath);
} else {
pm_printf(ALPM_LOG_WARNING, "%s: %s (%s)\n",
pkgname, filepath, strerror(errno));
}
return 1;
}
return 0;
}
int check_pkg_fast(alpm_pkg_t *pkg)
{
const char *root, *pkgname;
size_t errors = 0;
size_t rootlen;
char filepath[PATH_MAX];
alpm_filelist_t *filelist;
size_t i;
root = alpm_option_get_root(config->handle);
rootlen = strlen(root);
if(rootlen + 1 > PATH_MAX) {
pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, "");
return 1;
}
strcpy(filepath, root);
pkgname = alpm_pkg_get_name(pkg);
filelist = alpm_pkg_get_files(pkg);
for(i = 0; i < filelist->count; i++) {
const alpm_file_t *file = filelist->files + i;
struct stat st;
const char *path = file->name;
if(rootlen + 1 + strlen(path) > PATH_MAX) {
pm_printf(ALPM_LOG_WARNING, _("path too long: %s%s\n"), root, path);
continue;
}
strcpy(filepath + rootlen, path);
errors += check_file_exists(pkgname, filepath, &st);
}
if(!config->quiet) {
printf(_n("%s: %jd total file, ", "%s: %jd total files, ",
(unsigned long)filelist->count), pkgname, (intmax_t)filelist->count);
printf(_n("%jd missing file\n", "%jd missing files\n",
(unsigned long)errors), (intmax_t)errors);
}
return (errors != 0 ? 1 : 0);
}
int check_pkg_full(alpm_pkg_t *pkg)
{
const char *root, *pkgname;
size_t errors = 0;
size_t rootlen;
char filepath[PATH_MAX];
struct archive *mtree;
struct archive_entry *entry = NULL;
size_t file_count = 0;
root = alpm_option_get_root(config->handle);
rootlen = strlen(root);
if(rootlen + 1 > PATH_MAX) {
pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, "");
return 1;
}
strcpy(filepath, root);
pkgname = alpm_pkg_get_name(pkg);
mtree = alpm_pkg_mtree_open(pkg);
if(mtree == NULL) {
TODO
if(!config->quiet) {
printf(_("%s: no mtree file\n"), pkgname);
}
return 0;
}
while(alpm_pkg_mtree_next(pkg, mtree, &entry) == ARCHIVE_OK) {
struct stat st;
const char *path = archive_entry_pathname(entry);
TODO
if(*path == '.') {
continue;
}
file_count++;
if(rootlen + 1 + strlen(path) > PATH_MAX) {
pm_printf(ALPM_LOG_WARNING, _("path too long: %s%s\n"), root, path);
continue;
}
strcpy(filepath + rootlen, path);
if(check_file_exists(pkgname, filepath, &st) == 1) {
errors++;
continue;
}
TODO
}
alpm_pkg_mtree_close(pkg, mtree);
if(!config->quiet) {
printf(_n("%s: %jd total file, ", "%s: %jd total files, ",
(unsigned long)file_count), pkgname, (intmax_t)file_count);
printf(_n("%jd altered file\n", "%jd altered files\n",
(unsigned long)errors), (intmax_t)errors);
}
return (errors != 0 ? 1 : 0);
}
|