libopkg: store compressed package lists
[oweals/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 <stdio.h>
19
20 #include "hash_table.h"
21 #include "release.h"
22 #include "pkg.h"
23 #include "opkg_message.h"
24 #include "pkg_vec.h"
25 #include "pkg_hash.h"
26 #include "parse_util.h"
27 #include "pkg_parse.h"
28 #include "opkg_utils.h"
29 #include "sprintf_alloc.h"
30 #include "file_util.h"
31 #include "libbb/libbb.h"
32 #include "libbb/gzip.h"
33
34 void
35 pkg_hash_init(void)
36 {
37         hash_table_init("pkg-hash", &conf->pkg_hash,
38                         OPKG_CONF_DEFAULT_HASH_LEN);
39 }
40
41 static void
42 free_pkgs(const char *key, void *entry, void *data)
43 {
44         int i;
45         abstract_pkg_t *ab_pkg;
46
47         /* Each entry in the hash table is an abstract package, which contains
48          * a list of packages that provide the abstract package.
49          */
50
51         ab_pkg = (abstract_pkg_t*) entry;
52
53         if (ab_pkg->pkgs) {
54                 for (i = 0; i < ab_pkg->pkgs->len; i++) {
55                         pkg_deinit (ab_pkg->pkgs->pkgs[i]);
56                         free (ab_pkg->pkgs->pkgs[i]);
57                 }
58         }
59
60         abstract_pkg_vec_free (ab_pkg->provided_by);
61         abstract_pkg_vec_free (ab_pkg->replaced_by);
62         pkg_vec_free (ab_pkg->pkgs);
63         free (ab_pkg->depended_upon_by);
64         free (ab_pkg->name);
65         free (ab_pkg);
66 }
67
68 void
69 pkg_hash_deinit(void)
70 {
71         hash_table_foreach(&conf->pkg_hash, free_pkgs, NULL);
72         hash_table_deinit(&conf->pkg_hash);
73 }
74
75 int
76 dist_hash_add_from_file(const char *lists_dir, pkg_src_t *dist)
77 {
78         nv_pair_list_elt_t *l;
79         char *list_file, *subname;
80
81         list_for_each_entry(l , &conf->arch_list.head, node) {
82                 nv_pair_t *nv = (nv_pair_t *)l->data;
83                 sprintf_alloc(&subname, "%s-%s", dist->name, nv->name);
84                 sprintf_alloc(&list_file, "%s/%s", lists_dir, subname);
85
86                 if (file_exists(list_file)) {
87                         if (pkg_hash_add_from_file(list_file, dist, NULL, 0)) {
88                                 free(list_file);
89                                 return -1;
90                         }
91                         pkg_src_list_append (&conf->pkg_src_list, subname, dist->value, "__dummy__", 0);
92                 }
93
94                 free(list_file);
95         }
96
97         return 0;
98 }
99
100
101 int
102 pkg_hash_add_from_file(const char *file_name,
103                         pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
104 {
105         pkg_t *pkg;
106         FILE *fp;
107         char *buf;
108         const size_t len = 4096;
109         int ret = 0;
110         struct gzip_handle zh;
111
112         if (src && src->gzip) {
113                 fp = gzip_fdopen(&zh, file_name);
114         }
115         else {
116                 fp = fopen(file_name, "r");
117         }
118
119         if (fp == NULL) {
120                 opkg_perror(ERROR, "Failed to open %s", file_name);
121                 return -1;
122         }
123
124         buf = xmalloc(len);
125
126         do {
127                 pkg = pkg_new();
128                 pkg->src = src;
129                 pkg->dest = dest;
130
131                 ret = parse_from_stream_nomalloc(pkg_parse_line, pkg, fp, 0,
132                                 &buf, len);
133
134                 if (pkg->name == NULL) {
135                         /* probably just a blank line */
136                         ret = 1;
137                 }
138
139                 if (ret) {
140                         pkg_deinit (pkg);
141                         free(pkg);
142                         if (ret == -1)
143                                 break;
144                         if (ret == 1)
145                                 /* Probably a blank line, continue parsing. */
146                                 ret = 0;
147                         continue;
148                 }
149
150                 if (!pkg->architecture || !pkg->arch_priority) {
151                         char *version_str = pkg_version_str_alloc(pkg);
152                         opkg_msg(NOTICE, "Package %s version %s has no "
153                                         "valid architecture, ignoring.\n",
154                                         pkg->name, version_str);
155                         free(version_str);
156                         continue;
157                 }
158
159                 hash_insert_pkg(pkg, is_status_file);
160
161         } while (!feof(fp));
162
163         free(buf);
164         fclose(fp);
165
166         if (src && src->gzip)
167                 gzip_close(&zh);
168
169         return ret;
170 }
171
172 /*
173  * Load in feed files from the cached "src" and/or "src/gz" locations.
174  */
175 int
176 pkg_hash_load_feeds(void)
177 {
178         pkg_src_list_elt_t *iter;
179         pkg_src_t *src, *subdist;
180         char *list_file, *lists_dir;
181
182         opkg_msg(INFO, "\n");
183
184         lists_dir = conf->restrict_to_default_dest ?
185                 conf->default_dest->lists_dir : conf->lists_dir;
186
187         for (iter = void_list_first(&conf->dist_src_list); iter;
188                         iter = void_list_next(&conf->dist_src_list, iter)) {
189
190                 src = (pkg_src_t *)iter->data;
191
192                 sprintf_alloc(&list_file, "%s/%s", lists_dir, src->name);
193
194                 if (file_exists(list_file)) {
195                         int i;
196                         release_t *release = release_new();
197                         if(release_init_from_file(release, list_file)) {
198                                 free(list_file);
199                                 return -1;
200                         }
201
202                         unsigned int ncomp;
203                         const char **comps = release_comps(release, &ncomp);
204                         subdist = (pkg_src_t *) xmalloc(sizeof(pkg_src_t));
205                         memcpy(subdist, src, sizeof(pkg_src_t));
206
207                         for(i = 0; i < ncomp; i++){
208                                 subdist->name = NULL;
209                                 sprintf_alloc(&subdist->name, "%s-%s", src->name, comps[i]);
210                                 if (dist_hash_add_from_file(lists_dir, subdist)) {
211                                         free(subdist->name); free(subdist);
212                                         free(list_file);
213                                         return -1;
214                                 }
215                         }
216                         free(subdist->name); free(subdist);
217                 }
218                 free(list_file);
219         }
220
221         for (iter = void_list_first(&conf->pkg_src_list); iter;
222                         iter = void_list_next(&conf->pkg_src_list, iter)) {
223
224                 src = (pkg_src_t *)iter->data;
225
226                 sprintf_alloc(&list_file, "%s/%s", lists_dir, src->name);
227
228                 if (file_exists(list_file)) {
229                         if (pkg_hash_add_from_file(list_file, src, NULL, 0)) {
230                                 free(list_file);
231                                 return -1;
232                         }
233                 }
234                 free(list_file);
235         }
236
237         return 0;
238 }
239
240 /*
241  * Load in status files from the configured "dest"s.
242  */
243 int
244 pkg_hash_load_status_files(void)
245 {
246         pkg_dest_list_elt_t *iter;
247         pkg_dest_t *dest;
248
249         opkg_msg(INFO, "\n");
250
251         for (iter = void_list_first(&conf->pkg_dest_list); iter;
252                         iter = void_list_next(&conf->pkg_dest_list, iter)) {
253
254                 dest = (pkg_dest_t *)iter->data;
255
256                 if (file_exists(dest->status_file_name)) {
257                         if (pkg_hash_add_from_file(dest->status_file_name, NULL, dest, 1))
258                                 return -1;
259                 }
260         }
261
262         return 0;
263 }
264
265 static abstract_pkg_t *
266 abstract_pkg_fetch_by_name(const char * pkg_name)
267 {
268         return (abstract_pkg_t *)hash_table_get(&conf->pkg_hash, pkg_name);
269 }
270
271 pkg_t *
272 pkg_hash_fetch_best_installation_candidate(abstract_pkg_t *apkg,
273                 int (*constraint_fcn)(pkg_t *pkg, void *cdata),
274                 void *cdata, int quiet)
275 {
276      int i, j;
277      int nprovides = 0;
278      int nmatching = 0;
279      int wrong_arch_found = 0;
280      pkg_vec_t *matching_pkgs;
281      abstract_pkg_vec_t *matching_apkgs;
282      abstract_pkg_vec_t *provided_apkg_vec;
283      abstract_pkg_t **provided_apkgs;
284      abstract_pkg_vec_t *providers;
285      pkg_t *latest_installed_parent = NULL;
286      pkg_t *latest_matching = NULL;
287      pkg_t *priorized_matching = NULL;
288      pkg_t *held_pkg = NULL;
289      pkg_t *good_pkg_by_name = NULL;
290
291      if (apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
292           return NULL;
293
294      matching_pkgs = pkg_vec_alloc();
295      matching_apkgs = abstract_pkg_vec_alloc();
296      providers = abstract_pkg_vec_alloc();
297
298      opkg_msg(DEBUG, "Best installation candidate for %s:\n", apkg->name);
299
300      provided_apkg_vec = apkg->provided_by;
301      nprovides = provided_apkg_vec->len;
302      provided_apkgs = provided_apkg_vec->pkgs;
303      if (nprovides > 1)
304           opkg_msg(DEBUG, "apkg=%s nprovides=%d.\n", apkg->name, nprovides);
305
306      /* accumulate all the providers */
307      for (i = 0; i < nprovides; i++) {
308           abstract_pkg_t *provider_apkg = provided_apkgs[i];
309           opkg_msg(DEBUG, "Adding %s to providers.\n", provider_apkg->name);
310           abstract_pkg_vec_insert(providers, provider_apkg);
311      }
312      nprovides = providers->len;
313
314      for (i = 0; i < nprovides; i++) {
315           abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
316           abstract_pkg_t *replacement_apkg = NULL;
317           pkg_vec_t *vec;
318
319           if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
320                replacement_apkg = provider_apkg->replaced_by->pkgs[0];
321                if (provider_apkg->replaced_by->len > 1) {
322                     opkg_msg(NOTICE, "Multiple replacers for %s, "
323                                 "using first one (%s).\n",
324                                 provider_apkg->name, replacement_apkg->name);
325                }
326           }
327
328           if (replacement_apkg)
329                opkg_msg(DEBUG, "replacement_apkg=%s for provider_apkg=%s.\n",
330                             replacement_apkg->name, provider_apkg->name);
331
332           if (replacement_apkg && (replacement_apkg != provider_apkg)) {
333                if (abstract_pkg_vec_contains(providers, replacement_apkg))
334                     continue;
335                else
336                     provider_apkg = replacement_apkg;
337           }
338
339           if (!(vec = provider_apkg->pkgs)) {
340                opkg_msg(DEBUG, "No pkgs for provider_apkg %s.\n",
341                                provider_apkg->name);
342                continue;
343           }
344
345
346           /* now check for supported architecture */
347           {
348                int max_count = 0;
349
350                /* count packages matching max arch priority and keep track of last one */
351                for (j=0; j<vec->len; j++) {
352                     pkg_t *maybe = vec->pkgs[j];
353                     opkg_msg(DEBUG, "%s arch=%s arch_priority=%d version=%s.\n",
354                                  maybe->name, maybe->architecture,
355                                  maybe->arch_priority, maybe->version);
356                     /* We make sure not to add the same package twice. Need to search for the reason why
357                        they show up twice sometimes. */
358                     if ((maybe->arch_priority > 0) && (! pkg_vec_contains(matching_pkgs, maybe))) {
359                          max_count++;
360                          abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
361                          pkg_vec_insert(matching_pkgs, maybe);
362                     }
363                }
364
365                 if (vec->len > 0 && matching_pkgs->len < 1)
366                         wrong_arch_found = 1;
367           }
368      }
369
370      if (matching_pkgs->len < 1) {
371           if (wrong_arch_found)
372                 opkg_msg(ERROR, "Packages for %s found, but"
373                         " incompatible with the architectures configured\n",
374                         apkg->name);
375           pkg_vec_free(matching_pkgs);
376           abstract_pkg_vec_free(matching_apkgs);
377           abstract_pkg_vec_free(providers);
378           return NULL;
379      }
380
381
382      if (matching_pkgs->len > 1)
383           pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
384      if (matching_apkgs->len > 1)
385           abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
386
387      for (i = 0; i < matching_pkgs->len; i++) {
388           pkg_t *matching = matching_pkgs->pkgs[i];
389           if (constraint_fcn(matching, cdata)) {
390              opkg_msg(DEBUG, "Candidate: %s %s.\n",
391                              matching->name, matching->version) ;
392              good_pkg_by_name = matching;
393              /* It has been provided by hand, so it is what user want */
394              if (matching->provided_by_hand == 1)
395                 break;
396           }
397      }
398
399
400      for (i = 0; i < matching_pkgs->len; i++) {
401           pkg_t *matching = matching_pkgs->pkgs[i];
402           latest_matching = matching;
403           if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
404                latest_installed_parent = matching;
405           if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
406                if (held_pkg)
407                     opkg_msg(NOTICE, "Multiple packages (%s and %s) providing"
408                                 " same name marked HOLD or PREFER. "
409                                 "Using latest.\n",
410                                 held_pkg->name, matching->name);
411                held_pkg = matching;
412           }
413      }
414
415      if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
416           int prio = 0;
417           for (i = 0; i < matching_pkgs->len; i++) {
418               pkg_t *matching = matching_pkgs->pkgs[i];
419                   if (matching->arch_priority > prio) {
420                       priorized_matching = matching;
421                       prio = matching->arch_priority;
422                       opkg_msg(DEBUG, "Match %s with priority %i.\n",
423                                 matching->name, prio);
424                   }
425               }
426
427           }
428
429      if (conf->verbosity >= INFO && matching_apkgs->len > 1) {
430           opkg_msg(INFO, "%d matching pkgs for apkg=%s:\n",
431                                 matching_pkgs->len, apkg->name);
432           for (i = 0; i < matching_pkgs->len; i++) {
433                pkg_t *matching = matching_pkgs->pkgs[i];
434                opkg_msg(INFO, "%s %s %s\n",
435                         matching->name, matching->version,
436                         matching->architecture);
437           }
438      }
439
440      nmatching = matching_apkgs->len;
441
442      pkg_vec_free(matching_pkgs);
443      abstract_pkg_vec_free(matching_apkgs);
444      abstract_pkg_vec_free(providers);
445
446      if (good_pkg_by_name) {   /* We found a good candidate, we will install it */
447           return good_pkg_by_name;
448      }
449      if (held_pkg) {
450           opkg_msg(INFO, "Using held package %s.\n", held_pkg->name);
451           return held_pkg;
452      }
453      if (latest_installed_parent) {
454           opkg_msg(INFO, "Using latest version of installed package %s.\n",
455                         latest_installed_parent->name);
456           return latest_installed_parent;
457      }
458      if (priorized_matching) {
459           opkg_msg(INFO, "Using priorized matching %s %s %s.\n",
460                         priorized_matching->name, priorized_matching->version,
461                         priorized_matching->architecture);
462           return priorized_matching;
463      }
464      if (nmatching > 1) {
465           opkg_msg(INFO, "No matching pkg out of %d matching_apkgs.\n",
466                         nmatching);
467           return NULL;
468      }
469      if (latest_matching) {
470           opkg_msg(INFO, "Using latest matching %s %s %s.\n",
471                         latest_matching->name, latest_matching->version,
472                         latest_matching->architecture);
473           return latest_matching;
474      }
475      return NULL;
476 }
477
478 static int
479 pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
480 {
481         const char *name = (const char *)cdata;
482
483         if (strcmp(pkg->name, name) == 0)
484                 return 1;
485         else
486                 return 0;
487 }
488
489 static pkg_vec_t *
490 pkg_vec_fetch_by_name(const char *pkg_name)
491 {
492         abstract_pkg_t * ab_pkg;
493
494         if(!(ab_pkg = abstract_pkg_fetch_by_name(pkg_name)))
495                 return NULL;
496
497         if (ab_pkg->pkgs)
498                 return ab_pkg->pkgs;
499
500         if (ab_pkg->provided_by) {
501                 abstract_pkg_t *abpkg =  abstract_pkg_vec_get(ab_pkg->provided_by, 0);
502                 if (abpkg != NULL)
503                         return abpkg->pkgs;
504                 else
505                         return ab_pkg->pkgs;
506         }
507
508         return NULL;
509 }
510
511
512 pkg_t *
513 pkg_hash_fetch_best_installation_candidate_by_name(const char *name)
514 {
515         abstract_pkg_t *apkg = NULL;
516
517         if (!(apkg = abstract_pkg_fetch_by_name(name)))
518                 return NULL;
519
520         return pkg_hash_fetch_best_installation_candidate(apkg,
521                                 pkg_name_constraint_fcn, apkg->name, 0);
522 }
523
524
525 pkg_t *
526 pkg_hash_fetch_by_name_version(const char *pkg_name, const char * version)
527 {
528         pkg_vec_t * vec;
529         int i;
530         char *version_str = NULL;
531
532         if(!(vec = pkg_vec_fetch_by_name(pkg_name)))
533                 return NULL;
534
535         for(i = 0; i < vec->len; i++) {
536                 version_str = pkg_version_str_alloc(vec->pkgs[i]);
537                 if(!strcmp(version_str, version)) {
538                         free(version_str);
539                         break;
540                 }
541                 free(version_str);
542         }
543
544         if(i == vec->len)
545                 return NULL;
546
547         return vec->pkgs[i];
548 }
549
550 pkg_t *
551 pkg_hash_fetch_installed_by_name_dest(const char *pkg_name, pkg_dest_t *dest)
552 {
553         pkg_vec_t * vec;
554         int i;
555
556         if (!(vec = pkg_vec_fetch_by_name(pkg_name))) {
557                 return NULL;
558         }
559
560         for (i = 0; i < vec->len; i++)
561                 if((vec->pkgs[i]->state_status == SS_INSTALLED
562                                 || vec->pkgs[i]->state_status == SS_UNPACKED)
563                                 && vec->pkgs[i]->dest == dest) {
564                         return vec->pkgs[i];
565         }
566
567         return NULL;
568 }
569
570 pkg_t *
571 pkg_hash_fetch_installed_by_name(const char *pkg_name)
572 {
573         pkg_vec_t * vec;
574         int i;
575
576         if (!(vec = pkg_vec_fetch_by_name(pkg_name))) {
577                 return NULL;
578         }
579
580         for (i = 0; i < vec->len; i++) {
581                 if (vec->pkgs[i]->state_status == SS_INSTALLED
582                                 || vec->pkgs[i]->state_status == SS_UNPACKED) {
583                         return vec->pkgs[i];
584                 }
585         }
586
587         return NULL;
588 }
589
590
591 static void
592 pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
593 {
594         int j;
595         abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
596         pkg_vec_t *all = (pkg_vec_t *)data;
597         pkg_vec_t *pkg_vec = ab_pkg->pkgs;
598
599         if (!pkg_vec)
600                 return;
601
602         for (j = 0; j < pkg_vec->len; j++) {
603                 pkg_t *pkg = pkg_vec->pkgs[j];
604                 pkg_vec_insert(all, pkg);
605         }
606 }
607
608 void
609 pkg_hash_fetch_available(pkg_vec_t *all)
610 {
611         hash_table_foreach(&conf->pkg_hash, pkg_hash_fetch_available_helper,
612                         all);
613 }
614
615 static void
616 pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
617 {
618         abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
619         pkg_vec_t *all = (pkg_vec_t *)data;
620         pkg_vec_t *pkg_vec = ab_pkg->pkgs;
621         int j;
622
623         if (!pkg_vec)
624                 return;
625
626         for (j = 0; j < pkg_vec->len; j++) {
627                 pkg_t *pkg = pkg_vec->pkgs[j];
628                 if (pkg->state_status == SS_INSTALLED
629                                 || pkg->state_status == SS_UNPACKED)
630                         pkg_vec_insert(all, pkg);
631         }
632 }
633
634 void
635 pkg_hash_fetch_all_installed(pkg_vec_t *all)
636 {
637         hash_table_foreach(&conf->pkg_hash, pkg_hash_fetch_all_installed_helper,
638                         all);
639 }
640
641 /*
642  * This assumes that the abstract pkg doesn't exist.
643  */
644 static abstract_pkg_t *
645 add_new_abstract_pkg_by_name(const char *pkg_name)
646 {
647         abstract_pkg_t *ab_pkg;
648
649         ab_pkg = abstract_pkg_new();
650
651         ab_pkg->name = xstrdup(pkg_name);
652         hash_table_insert(&conf->pkg_hash, pkg_name, ab_pkg);
653
654         return ab_pkg;
655 }
656
657
658 abstract_pkg_t *
659 ensure_abstract_pkg_by_name(const char *pkg_name)
660 {
661         abstract_pkg_t * ab_pkg;
662
663         if (!(ab_pkg = abstract_pkg_fetch_by_name(pkg_name)))
664                 ab_pkg = add_new_abstract_pkg_by_name(pkg_name);
665
666         return ab_pkg;
667 }
668
669 void
670 hash_insert_pkg(pkg_t *pkg, int set_status)
671 {
672         abstract_pkg_t * ab_pkg;
673
674         ab_pkg = ensure_abstract_pkg_by_name(pkg->name);
675         if (!ab_pkg->pkgs)
676                 ab_pkg->pkgs = pkg_vec_alloc();
677
678         if (pkg->state_status == SS_INSTALLED) {
679                 ab_pkg->state_status = SS_INSTALLED;
680         } else if (pkg->state_status == SS_UNPACKED) {
681                 ab_pkg->state_status = SS_UNPACKED;
682         }
683
684         buildDepends(pkg);
685
686         buildProvides(ab_pkg, pkg);
687
688         /* Need to build the conflicts graph before replaces for correct
689          * calculation of replaced_by relation.
690          */
691         buildConflicts(pkg);
692
693         buildReplaces(ab_pkg, pkg);
694
695         buildDependedUponBy(pkg, ab_pkg);
696
697         pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status);
698         pkg->parent = ab_pkg;
699 }
700
701 static const char *
702 strip_offline_root(const char *file_name)
703 {
704         unsigned int len;
705
706         if (conf->offline_root) {
707                 len = strlen(conf->offline_root);
708                 if (strncmp(file_name, conf->offline_root, len) == 0)
709                         file_name += len;
710         }
711
712         return file_name;
713 }
714
715 void
716 file_hash_remove(const char *file_name)
717 {
718         file_name = strip_offline_root(file_name);
719         hash_table_remove(&conf->file_hash, file_name);
720 }
721
722 pkg_t *
723 file_hash_get_file_owner(const char *file_name)
724 {
725         file_name = strip_offline_root(file_name);
726         return hash_table_get(&conf->file_hash, file_name);
727 }
728
729 void
730 file_hash_set_file_owner(const char *file_name, pkg_t *owning_pkg)
731 {
732         pkg_t *old_owning_pkg;
733         int file_name_len = strlen(file_name);
734
735         if (file_name[file_name_len -1] == '/')
736                 return;
737
738         file_name = strip_offline_root(file_name);
739
740         old_owning_pkg = hash_table_get(&conf->file_hash, file_name);
741         hash_table_insert(&conf->file_hash, file_name, owning_pkg);
742
743         if (old_owning_pkg) {
744                 pkg_get_installed_files(old_owning_pkg);
745                 str_list_remove_elt(old_owning_pkg->installed_files, file_name);
746                 pkg_free_installed_files(old_owning_pkg);
747
748                 /* mark this package to have its filelist written */
749                 old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
750                 owning_pkg->state_flag |= SF_FILELIST_CHANGED;
751         }
752 }