@@ -166,11 +166,10 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
166
166
{
167
167
struct qfile_opt_state * state = priv ;
168
168
const char * catname = pkg_ctx -> cat_ctx -> name ;
169
- char * real_root = state -> real_root ;
170
169
qfile_args_t * args = & state -> args ;
171
170
qfile_str_len_t * base_names = args -> basenames ;
172
171
qfile_str_len_t * dir_names = args -> dirnames ;
173
- qfile_str_len_t * real_dir_names = args -> dirnames ;
172
+ qfile_str_len_t * real_dir_names = args -> realdirnames ;
174
173
short * non_orphans = args -> non_orphans ;
175
174
int * results = args -> results ;
176
175
char * line ;
@@ -239,23 +238,22 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
239
238
240
239
path_ok = false;
241
240
242
- if (dir_names [i ].len > 0 &&
243
- dir_names [i ].len == dirname_len &&
241
+ if (dir_names [i ].len == dirname_len &&
244
242
memcmp (e -> name , dir_names [i ].str , dir_names [i ].len ) == 0 )
245
243
{
246
244
/* dir_name == dirname(CONTENTS) */
247
245
path_ok = true;
248
- } else if (real_dir_names [i ].len > 0 &&
249
- real_dir_names [i ].len == dirname_len &&
246
+ } else if (real_dir_names [i ].len == dirname_len &&
250
247
memcmp (e -> name , real_dir_names [i ].str ,
251
248
real_dir_names [i ].len ) == 0 )
252
249
{
253
250
/* real_dir_name == dirname(CONTENTS) */
254
251
path_ok = true;
255
- } else if (real_root [ 0 ] ) {
252
+ } else if (state -> real_root_len > 0 ) {
256
253
char rpath [_Q_PATH_MAX + 1 ];
257
254
char * _rpath ;
258
255
char fullpath [_Q_PATH_MAX + 1 ];
256
+ char * real_root = state -> real_root ;
259
257
size_t real_root_len = state -> real_root_len ;
260
258
261
259
snprintf (fullpath , sizeof (fullpath ), "%s%s" ,
@@ -275,6 +273,7 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
275
273
warn ("Real path of \"%s\" is not under ROOT: %s" ,
276
274
fullpath , rpath );
277
275
} else if (dir_names [i ].len > 0 &&
276
+ real_dir_names [i ].len == 0 &&
278
277
strcmp (_rpath , dir_names [i ].str ) == 0 ) {
279
278
/* dir_name == realpath(dirname(CONTENTS)) */
280
279
path_ok = true;
@@ -444,7 +443,7 @@ prepare_qfile_args(const int argc, const char **argv, struct qfile_opt_state *st
444
443
tmppath , abspath );
445
444
goto skip_query_item ;
446
445
}
447
- if (strcmp (dirnames [i ].str , abspath + real_root_len ))
446
+ if (strcmp (dirnames [i ].str , abspath + real_root_len ) != 0 )
448
447
{
449
448
realdirnames [i ].str = xstrdup (abspath + real_root_len );
450
449
realdirnames [i ].len = strlen (realdirnames [i ].str );
@@ -567,12 +566,13 @@ int qfile_main(int argc, char **argv)
567
566
state .pwd = xstrdup (state .pwd );
568
567
if (state .pwd [lastc ] == '/' )
569
568
state .pwd [lastc ] = '\0' ;
569
+ state .pwd_len = strlen (state .pwd );
570
570
}
571
571
572
572
/* Get realpath of $ROOT, with no trailing slash */
573
573
if (portroot [0 ] == '/' )
574
574
p = realpath (portroot , NULL );
575
- else if (state .pwd ) {
575
+ else if (state .pwd_len > 0 ) {
576
576
snprintf (state .buf , state .buflen , "%s/%s" , state .pwd , portroot );
577
577
p = realpath (state .buf , NULL );
578
578
} else
0 commit comments