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