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