Lines 51-56
Link Here
|
51 |
char *bn_firstchars; |
51 |
char *bn_firstchars; |
52 |
short *non_orphans; |
52 |
short *non_orphans; |
53 |
char *real_root; |
53 |
char *real_root; |
|
|
54 |
size_t real_root_length; |
54 |
char *exclude_pkg; |
55 |
char *exclude_pkg; |
55 |
char *exclude_slot; |
56 |
char *exclude_slot; |
56 |
} qfile_args_t; |
57 |
} qfile_args_t; |
Lines 75-86
Link Here
|
75 |
int i, path_ok; |
76 |
int i, path_ok; |
76 |
char bn_firstchar; |
77 |
char bn_firstchar; |
77 |
char *real_root = args->real_root; |
78 |
char *real_root = args->real_root; |
|
|
79 |
size_t real_root_len = args->real_root_length; |
78 |
char **base_names = args->basenames; |
80 |
char **base_names = args->basenames; |
79 |
char **dir_names = args->dirnames; |
81 |
char **dir_names = args->dirnames; |
80 |
char **real_dir_names = args->realdirnames; |
82 |
char **real_dir_names = args->realdirnames; |
81 |
char *bn_firstchars = args->bn_firstchars; |
83 |
char *bn_firstchars = args->bn_firstchars; |
82 |
short *non_orphans = args->non_orphans; |
84 |
short *non_orphans = args->non_orphans; |
83 |
|
85 |
|
|
|
86 |
// these variables are for checking realpath(dirname(CONTENTS)) |
87 |
char rpath[_Q_PATH_MAX + 1]; |
88 |
char *_rpath = rpath + real_root_len; |
89 |
char fullpath[_Q_PATH_MAX + 1]; |
90 |
memcpy(fullpath, real_root, real_root_len); |
91 |
fullpath[real_root_len] = '\0'; |
92 |
|
84 |
if ((dir = opendir(path)) == NULL) { |
93 |
if ((dir = opendir(path)) == NULL) { |
85 |
warnp("opendir(%s) failed", path); |
94 |
warnp("opendir(%s) failed", path); |
86 |
return; |
95 |
return; |
Lines 186-200
Link Here
|
186 |
/* real_dir_name == dirname(CONTENTS) */ |
195 |
/* real_dir_name == dirname(CONTENTS) */ |
187 |
path_ok = 1; |
196 |
path_ok = 1; |
188 |
|
197 |
|
189 |
else if (real_root[0]) { |
198 |
else { |
190 |
char rpath[_Q_PATH_MAX + 1], *_rpath; |
199 |
/* reuse realpath(dirname(...)) from a previous CONTENTS entry |
191 |
char *fullpath; |
200 |
* if directory has not changed yet */ |
192 |
size_t real_root_len = strlen(real_root); |
201 |
if ((fullpath[0] == '\0') || |
193 |
|
202 |
(fullpath[real_root_len + dirname_len] != '\0') || |
194 |
xasprintf(&fullpath, "%s%s", real_root, e->name); |
203 |
(strncmp(fullpath + real_root_len, e->name, dirname_len))) |
195 |
fullpath[real_root_len + dirname_len] = '\0'; |
204 |
{ |
196 |
_rpath = rpath + real_root_len; |
205 |
rpath[0] = '\0'; |
197 |
if (realpath(fullpath, rpath) == NULL) { |
206 |
memcpy(fullpath + real_root_len, e->name, dirname_len); |
|
|
207 |
fullpath[real_root_len + dirname_len] = '\0'; |
208 |
if (realpath(fullpath, rpath) == NULL) |
209 |
rpath[0] = '\0'; |
210 |
} |
211 |
|
212 |
if (rpath[0] == '\0') { |
198 |
if (verbose) { |
213 |
if (verbose) { |
199 |
warnp("Could not read real path of \"%s\" (from %s)", fullpath, pkg); |
214 |
warnp("Could not read real path of \"%s\" (from %s)", fullpath, pkg); |
200 |
warn("We'll never know whether \"%s\" was a result for your query...", |
215 |
warn("We'll never know whether \"%s\" was a result for your query...", |
Lines 212-218
Link Here
|
212 |
/* real_dir_name == realpath(dirname(CONTENTS)) */ |
227 |
/* real_dir_name == realpath(dirname(CONTENTS)) */ |
213 |
path_ok = 1; |
228 |
path_ok = 1; |
214 |
} |
229 |
} |
215 |
free(fullpath); |
|
|
216 |
} |
230 |
} |
217 |
} |
231 |
} |
218 |
if (!path_ok) |
232 |
if (!path_ok) |
Lines 311-317
Link Here
|
311 |
int i; |
325 |
int i; |
312 |
int nb_of_queries = argc; |
326 |
int nb_of_queries = argc; |
313 |
char *pwd = NULL; |
327 |
char *pwd = NULL; |
314 |
int real_root_length; |
328 |
size_t real_root_length; |
315 |
char *real_root = NULL; |
329 |
char *real_root = NULL; |
316 |
char **basenames = NULL; |
330 |
char **basenames = NULL; |
317 |
char **dirnames = NULL; |
331 |
char **dirnames = NULL; |
Lines 455-460
Link Here
|
455 |
free(pwd); |
469 |
free(pwd); |
456 |
|
470 |
|
457 |
qfile_args->real_root = real_root; |
471 |
qfile_args->real_root = real_root; |
|
|
472 |
qfile_args->real_root_length = real_root_length; |
458 |
qfile_args->basenames = basenames; |
473 |
qfile_args->basenames = basenames; |
459 |
qfile_args->dirnames = dirnames; |
474 |
qfile_args->dirnames = dirnames; |
460 |
qfile_args->realdirnames = realdirnames; |
475 |
qfile_args->realdirnames = realdirnames; |