opkg: (leak fixing, day 2) lots and lots of memory leaks fixed
[project/opkg-lede.git] / libopkg / pkg_hash.c
1 /* opkg_hash.c - the opkg package management system
2
3 Steven M. Ayer
4
5 Copyright (C) 2002 Compaq Computer Corporation
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16 */
17
18 #include "includes.h"
19 #include <errno.h>
20 #include <ctype.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include "hash_table.h"
25 #include "pkg.h"
26 #include "opkg_message.h"
27 #include "pkg_vec.h"
28 #include "pkg_hash.h"
29 #include "pkg_parse.h"
30 #include "opkg_utils.h"
31
32 static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name);
33
34 /*
35 * this will talk to both feeds-lists files and installed status files
36 * example api:
37 *
38 * hash_table_t hash;
39 * pkg_hash_init(name, &hash, 1000);
40 * pkg_hash_add_from_file(<feed filename>);
41 *
42 * the query function is just there as a shell to prove to me that this
43 * sort of works, but isn't far from doing something useful
44 *
45 * -sma, 12/21/01
46 * modified: CDW 3 Jan. 2002
47 */
48
49
50 \f
51 int pkg_hash_init(const char *name, hash_table_t *hash, int len)
52 {
53 return hash_table_init(name, hash, len);
54 }
55
56 void free_pkgs (const char *key, void *entry, void *data)
57 {
58 int i;
59 abstract_pkg_t *ab_pkg;
60
61 /* each entry in the hash table is an abstract package, which contains a list
62 * of packages that provide the abstract package */
63
64 ab_pkg = (abstract_pkg_t*) entry;
65
66 if (ab_pkg->pkgs)
67 {
68 for (i = 0; i < ab_pkg->pkgs->len; i++)
69 {
70 pkg_deinit (ab_pkg->pkgs->pkgs[i]);
71 free (ab_pkg->pkgs->pkgs[i]);
72 }
73 }
74
75 abstract_pkg_vec_free (ab_pkg->provided_by);
76 abstract_pkg_vec_free (ab_pkg->replaced_by);
77 pkg_vec_free (ab_pkg->pkgs);
78 free (ab_pkg->depended_upon_by);
79 free (ab_pkg->name);
80 free (ab_pkg);
81 }
82
83 void pkg_hash_deinit(hash_table_t *hash)
84 {
85 hash_table_foreach (hash, free_pkgs, NULL);
86 hash_table_deinit(hash);
87 }
88
89
90 /* Find the default arch for a given package status file if none is given. */
91 static char *pkg_get_default_arch(opkg_conf_t *conf)
92 {
93 nv_pair_list_elt_t *l;
94 char *def_arch = HOST_CPU_STR; /* Default arch */
95 int def_prio = 0; /* Other archs override this */
96
97 l = conf->arch_list.head;
98
99 while (l) {
100 nv_pair_t *nv = l->data;
101 int priority = strtol(nv->value, NULL, 0);
102
103 /* Check if this arch has higher priority, and is valid */
104 if ((priority > def_prio) &&
105 (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) {
106 /* Our new default */
107 def_prio = priority;
108 def_arch = nv->name;
109 }
110 l = l->next;
111 }
112
113 return strdup(def_arch);
114 }
115
116 int pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name,
117 pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
118 {
119 hash_table_t *hash = &conf->pkg_hash;
120 char **raw;
121 char **raw_start;
122 pkg_t *pkg;
123
124 raw = raw_start = read_raw_pkgs_from_file(file_name);
125 if (!raw)
126 return -ENOMEM;
127
128 while(*raw){ /* don't worry, we'll increment raw in the parsing function */
129 pkg = pkg_new();
130 if (!pkg)
131 return -ENOMEM;
132
133 if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
134 if (!pkg->architecture) {
135 char *version_str = pkg_version_str_alloc(pkg);
136 pkg->architecture = pkg_get_default_arch(conf);
137 opkg_message(conf, OPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
138 pkg->name, version_str, pkg->architecture);
139 free(version_str);
140 }
141 hash_insert_pkg(hash, pkg, is_status_file,conf);
142 } else {
143 free(pkg);
144 }
145 }
146
147 /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
148 memory after read_raw_pkgs_from_file */
149 raw = raw_start;
150 while (*raw) {
151 free(*raw++);
152 }
153 free(raw_start);
154 return 0;
155 }
156
157 abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
158 {
159 return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
160 }
161
162 abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
163 {
164 abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
165 if (apkg)
166 return NULL;
167 return apkg->provided_by;
168 }
169
170
171 pkg_t *pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, abstract_pkg_t *apkg,
172 int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
173 {
174 int i;
175 int nprovides = 0;
176 int nmatching = 0;
177 pkg_vec_t *matching_pkgs = pkg_vec_alloc();
178 abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
179 abstract_pkg_vec_t *provided_apkg_vec;
180 abstract_pkg_t **provided_apkgs;
181 abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
182 pkg_t *latest_installed_parent = NULL;
183 pkg_t *latest_matching = NULL;
184 pkg_t *held_pkg = NULL;
185 pkg_t *good_pkg_by_name = NULL;
186
187 if (matching_apkgs == NULL || providers == NULL ||
188 apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
189 return NULL;
190
191 opkg_message(conf, OPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
192
193 provided_apkg_vec = apkg->provided_by;
194 nprovides = provided_apkg_vec->len;
195 provided_apkgs = provided_apkg_vec->pkgs;
196 if (nprovides > 1)
197 opkg_message(conf, OPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
198
199 /* accumulate all the providers */
200 for (i = 0; i < nprovides; i++) {
201 abstract_pkg_t *provider_apkg = provided_apkgs[i];
202 opkg_message(conf, OPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
203 abstract_pkg_vec_insert(providers, provider_apkg);
204 }
205 nprovides = providers->len;
206
207 for (i = 0; i < nprovides; i++) {
208 abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
209 abstract_pkg_t *replacement_apkg = NULL;
210 pkg_vec_t *vec;
211
212 if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
213 replacement_apkg = provider_apkg->replaced_by->pkgs[0];
214 if (provider_apkg->replaced_by->len > 1) {
215 opkg_message(conf, OPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n",
216 provider_apkg->name, replacement_apkg->name);
217 }
218 }
219
220 if (replacement_apkg)
221 opkg_message(conf, OPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n",
222 replacement_apkg->name, provider_apkg->name);
223
224 if (replacement_apkg && (replacement_apkg != provider_apkg)) {
225 if (abstract_pkg_vec_contains(providers, replacement_apkg))
226 continue;
227 else
228 provider_apkg = replacement_apkg;
229 }
230
231 if (!(vec = provider_apkg->pkgs)) {
232 opkg_message(conf, OPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name);
233 continue;
234 }
235
236
237 /* now check for supported architecture */
238 {
239 int max_count = 0;
240 int i;
241
242 /* count packages matching max arch priority and keep track of last one */
243 for (i = 0; i < vec->len; i++) {
244 pkg_t *maybe = vec->pkgs[i];
245 opkg_message(conf, OPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n",
246 maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
247 if (maybe->arch_priority > 0) {
248 max_count++;
249 abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
250 pkg_vec_insert(matching_pkgs, maybe);
251 }
252 }
253 }
254 }
255
256 if (matching_pkgs->len > 1)
257 pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
258 if (matching_apkgs->len > 1)
259 abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
260
261 /* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
262 needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
263 /* The problem is what to do when there are more than a mathing package, with the same name and several version ?
264 Until now I always got the latest, but that breaks the downgrade option.
265 If I stop at the first one, I would probably miss the new ones
266 Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
267 or from a Packages feed.
268 It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/
269 /*Pigi*/
270
271 for (i = 0; i < matching_pkgs->len; i++) {
272 pkg_t *matching = matching_pkgs->pkgs[i];
273 if (constraint_fcn(matching, cdata)) { /* We found it */
274 opkg_message(conf, OPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ;
275 good_pkg_by_name = matching;
276 if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */
277 break;
278 }
279 }
280
281
282 for (i = 0; i < matching_pkgs->len; i++) {
283 pkg_t *matching = matching_pkgs->pkgs[i];
284 latest_matching = matching;
285 if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
286 latest_installed_parent = matching;
287 if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
288 if (held_pkg)
289 opkg_message(conf, OPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n",
290 held_pkg->name, matching->name);
291 held_pkg = matching;
292 }
293 }
294
295 if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
296 opkg_message(conf, OPKG_ERROR, "Package=%s, %d matching providers\n",
297 apkg->name, matching_apkgs->len);
298 for (i = 0; i < matching_apkgs->len; i++) {
299 abstract_pkg_t *matching = matching_apkgs->pkgs[i];
300 opkg_message(conf, OPKG_ERROR, " %s\n", matching->name);
301 }
302 opkg_message(conf, OPKG_ERROR, "Please select one with opkg install or opkg flag prefer\n");
303 }
304
305 if (matching_apkgs->len > 1 && conf->verbosity > 1) {
306 opkg_message(conf, OPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
307 __FUNCTION__, apkg->name, matching_pkgs->len);
308 for (i = 0; i < matching_pkgs->len; i++) {
309 pkg_t *matching = matching_pkgs->pkgs[i];
310 opkg_message(conf, OPKG_INFO, " %s %s %s\n",
311 matching->name, matching->version, matching->architecture);
312 }
313 }
314
315 nmatching = matching_apkgs->len;
316
317 pkg_vec_free(matching_pkgs);
318 abstract_pkg_vec_free(matching_apkgs);
319 abstract_pkg_vec_free(providers);
320
321 if (good_pkg_by_name) { /* We found a good candidate, we will install it */
322 return good_pkg_by_name;
323 }
324 if (held_pkg) {
325 opkg_message(conf, OPKG_INFO, " using held package %s\n", held_pkg->name);
326 return held_pkg;
327 }
328 if (latest_installed_parent) {
329 opkg_message(conf, OPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name);
330 return latest_installed_parent;
331 }
332 if (nmatching > 1) {
333 opkg_message(conf, OPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching);
334 return NULL;
335 }
336 if (latest_matching) {
337 opkg_message(conf, OPKG_INFO, " using latest matching %s %s %s\n",
338 latest_matching->name, latest_matching->version, latest_matching->architecture);
339 return latest_matching;
340 }
341 return NULL;
342 }
343
344 static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
345 {
346 const char *name = (const char *)cdata;
347 if (strcmp(pkg->name, name) == 0)
348 return 1;
349 else
350 return 0;
351 }
352
353 pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(opkg_conf_t *conf, const char *name)
354 {
355 hash_table_t *hash = &conf->pkg_hash;
356 abstract_pkg_t *apkg = NULL;
357
358 if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
359 return NULL;
360
361 return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
362 }
363
364
365 pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash,
366 const char *pkg_name,
367 const char * version)
368 {
369 pkg_vec_t * vec;
370 register int i;
371 char *version_str = NULL;
372
373 if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
374 return NULL;
375
376 for(i = 0; i < vec->len; i++) {
377 version_str = pkg_version_str_alloc(vec->pkgs[i]);
378 if(!strcmp(version_str, version)) {
379 free(version_str);
380 break;
381 }
382 free(version_str);
383 }
384
385 if(i == vec->len)
386 return NULL;
387
388 return vec->pkgs[i];
389 }
390
391 pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
392 const char *pkg_name,
393 pkg_dest_t *dest)
394 {
395 pkg_vec_t * vec;
396 register int i;
397
398 if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
399 return NULL;
400 }
401
402 for(i = 0; i < vec->len; i++)
403 if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
404 return vec->pkgs[i];
405 }
406 return NULL;
407 }
408
409 pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
410 const char *pkg_name)
411 {
412 pkg_vec_t * vec;
413 register int i;
414
415 if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
416 return NULL;
417 }
418
419 for(i = 0; i < vec->len; i++)
420 if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
421 return vec->pkgs[i];
422 }
423
424 return NULL;
425 }
426
427 pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
428 {
429 abstract_pkg_t * ab_pkg;
430
431 if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
432 return NULL;
433 }
434
435 if (ab_pkg->pkgs) {
436 return ab_pkg->pkgs;
437 } else if (ab_pkg->provided_by) {
438 abstract_pkg_t *abpkg = abstract_pkg_vec_get(ab_pkg->provided_by, 0);
439 if (abpkg != NULL){
440 return abpkg->pkgs;
441 } else {
442 return ab_pkg->pkgs;
443 }
444 } else {
445 return NULL;
446 }
447 }
448
449 static int pkg_compare_names(const void *p1, const void *p2)
450 {
451 const pkg_t *pkg1 = *(const pkg_t **)p1;
452 const pkg_t *pkg2 = *(const pkg_t **)p2;
453 if (pkg1->name == NULL)
454 return 1;
455 if (pkg2->name == NULL)
456 return -1;
457 return(strcmp(pkg1->name, pkg2->name));
458 }
459
460
461 static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
462 {
463 int j;
464 abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
465 pkg_vec_t *all = (pkg_vec_t *)data;
466 pkg_vec_t *pkg_vec = ab_pkg->pkgs;
467 if (pkg_vec) {
468 for (j = 0; j < pkg_vec->len; j++) {
469 pkg_t *pkg = pkg_vec->pkgs[j];
470 pkg_vec_insert(all, pkg);
471 }
472 }
473 }
474
475 void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
476 {
477 hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
478 qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
479 }
480
481 static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
482 {
483 abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
484 pkg_vec_t *all = (pkg_vec_t *)data;
485 pkg_vec_t *pkg_vec = ab_pkg->pkgs;
486 int j;
487 if (pkg_vec) {
488 for (j = 0; j < pkg_vec->len; j++) {
489 pkg_t *pkg = pkg_vec->pkgs[j];
490 if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
491 pkg_vec_insert(all, pkg);
492 }
493 }
494 }
495 }
496 void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
497 {
498 hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
499 qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
500 }
501
502 static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
503 {
504 int i;
505 pkg_t *pkg;
506 abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
507 opkg_conf_t *conf = (opkg_conf_t *)data;
508 abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
509 fprintf(stdout, "%s\n", ab_pkg->name);
510 i = 0;
511 if (dependents != NULL)
512 while (dependents [i] != NULL)
513 printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
514 dependents = ab_pkg->provided_by->pkgs;
515 i = 0;
516 if (dependents != NULL)
517 while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
518 printf ("\tprovided by - %s\n", dependents [i ++]->name);
519 pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
520 if (pkg) {
521 i = 0;
522 while (i < pkg->depends_count)
523 printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);
524 }
525 }
526 void pkg_hash_dump(hash_table_t *hash, void *data)
527 {
528
529 printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
530 hash_table_foreach(hash, pkg_hash_dump_helper, data);
531 printf ("\n+=+%s+=+\n\n", __FUNCTION__);
532 }
533
534 abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
535 {
536 abstract_pkg_t * ab_pkg;
537
538 if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
539 ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
540
541 return ab_pkg;
542 }
543
544 pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,opkg_conf_t *conf)
545 {
546 abstract_pkg_t * ab_pkg;
547 int arch_priority;
548
549 if(!pkg)
550 return pkg;
551
552 arch_priority = pkg->arch_priority;
553
554 if (buildDepends(hash, pkg)<0){
555 fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
556 return NULL;
557 }
558 ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
559
560 if (set_status) {
561 if (pkg->state_status == SS_INSTALLED) {
562 ab_pkg->state_status = SS_INSTALLED;
563 } else if (pkg->state_status == SS_UNPACKED) {
564 ab_pkg->state_status = SS_UNPACKED;
565 }
566 }
567
568 if(!ab_pkg->pkgs)
569 ab_pkg->pkgs = pkg_vec_alloc();
570
571 /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
572 pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
573 pkg->parent = ab_pkg;
574
575 if (buildProvides(hash, ab_pkg, pkg)<0){
576 fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
577 return NULL;
578 }
579 /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
580 if (buildConflicts(hash, ab_pkg, pkg)<0){
581 fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
582 return NULL;
583 }
584 if (buildReplaces(hash, ab_pkg, pkg)<0) {
585 fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
586 return NULL;
587 }
588
589 buildDependedUponBy(pkg, ab_pkg);
590 return pkg;
591 }
592
593 /*
594 * this will assume that we've already determined that
595 * the abstract pkg doesn't exist, 'cause we should know these things...
596 */
597 static abstract_pkg_t * add_new_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
598 {
599 abstract_pkg_t * ab_pkg;
600
601 ab_pkg = abstract_pkg_new();
602 if (ab_pkg == NULL) { return NULL; }
603
604 ab_pkg->name = strdup(pkg_name);
605 hash_table_insert(hash, pkg_name, ab_pkg);
606
607 return ab_pkg;
608 }
609
610
611 pkg_t *file_hash_get_file_owner(opkg_conf_t *conf, const char *file_name)
612 {
613 hash_table_t *file_hash = &conf->file_hash;
614
615 return hash_table_get(file_hash, file_name);
616 }
617
618 int file_hash_set_file_owner(opkg_conf_t *conf, const char *file_name, pkg_t *owning_pkg)
619 {
620 hash_table_t *file_hash = &conf->file_hash;
621 pkg_t *old_owning_pkg = hash_table_get(file_hash, file_name);
622 int file_name_len = strlen(file_name);
623
624 if (file_name[file_name_len -1] == '/')
625 return 0;
626
627 if (conf->offline_root) {
628 int len = strlen(conf->offline_root);
629 if (strncmp(file_name, conf->offline_root, len) == 0) {
630 file_name += len;
631 }
632 }
633
634 // opkg_message(conf, OPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
635 hash_table_insert(file_hash, file_name, owning_pkg);
636 if (old_owning_pkg) {
637 str_list_remove_elt(old_owning_pkg->installed_files, file_name);
638 /* mark this package to have its filelist written */
639 old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
640 owning_pkg->state_flag |= SF_FILELIST_CHANGED;
641 }
642 return 0;
643 }
644
645