opkg: (leak fixing, day 1) lots and lots of memory leaks fixed
[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
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   pkg_vec_free (ab_pkg->pkgs);
77   free (ab_pkg->name);
78   free (ab_pkg);
79 }
80
81 void pkg_hash_deinit(hash_table_t *hash)
82 {
83   hash_table_foreach (hash, free_pkgs, NULL);
84   hash_table_deinit(hash);
85 }
86
87
88 /* Find the default arch for a given package status file if none is given. */
89 static char *pkg_get_default_arch(opkg_conf_t *conf)
90 {
91      nv_pair_list_elt_t *l;
92      char *def_arch = HOST_CPU_STR;             /* Default arch */
93      int def_prio = 0;                          /* Other archs override this */
94
95      l = conf->arch_list.head;
96
97      while (l) {
98           nv_pair_t *nv = 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           l = l->next;
109      }
110
111      return strdup(def_arch);
112 }
113
114 int pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name,
115                            pkg_src_t *src, pkg_dest_t *dest, int is_status_file)
116 {
117      hash_table_t *hash = &conf->pkg_hash;
118      char **raw;
119      char **raw_start;
120      pkg_t *pkg;
121     
122      raw = raw_start = read_raw_pkgs_from_file(file_name);
123      if (!raw)
124         return -ENOMEM;
125
126      while(*raw){         /* don't worry, we'll increment raw in the parsing function */
127           pkg = pkg_new();
128           if (!pkg)
129                return -ENOMEM;
130
131           if (pkg_parse_raw(pkg, &raw, src, dest) == 0) {
132                if (!pkg->architecture) {
133                     char *version_str = pkg_version_str_alloc(pkg);
134                     pkg->architecture = pkg_get_default_arch(conf);
135                     opkg_message(conf, OPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n",
136                                  pkg->name, version_str, pkg->architecture);
137                     free(version_str);
138                }
139                hash_insert_pkg(hash, pkg, is_status_file,conf);
140           } else {
141                free(pkg);
142           }
143      }
144
145      /* XXX: CLEANUP: I'd like a cleaner interface for cleaning up
146         memory after read_raw_pkgs_from_file */
147      raw = raw_start;
148      while (*raw) {
149           free(*raw++);
150      }
151      free(raw_start);
152      return 0;
153 }
154
155 abstract_pkg_t * abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name)
156 {
157   return (abstract_pkg_t *)hash_table_get(hash, pkg_name);
158 }
159
160 abstract_pkg_vec_t *pkg_hash_fetch_all_installation_candidates(hash_table_t *hash, const char *name)
161 {
162     abstract_pkg_t *apkg = abstract_pkg_fetch_by_name(hash, name);
163     if (apkg)
164        return NULL;
165     return apkg->provided_by;
166 }
167
168
169 pkg_t *pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, abstract_pkg_t *apkg, 
170                                                   int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet)
171 {
172      int i; 
173      int nprovides = 0;
174      int nmatching = 0;
175      pkg_vec_t *matching_pkgs = pkg_vec_alloc();
176      abstract_pkg_vec_t *matching_apkgs = abstract_pkg_vec_alloc();
177      abstract_pkg_vec_t *provided_apkg_vec;
178      abstract_pkg_t **provided_apkgs;
179      abstract_pkg_vec_t *providers = abstract_pkg_vec_alloc();
180      pkg_t *latest_installed_parent = NULL;
181      pkg_t *latest_matching = NULL;
182      pkg_t *held_pkg = NULL;
183      pkg_t *good_pkg_by_name = NULL;
184
185      if (matching_apkgs == NULL || providers == NULL || 
186          apkg == NULL || apkg->provided_by == NULL || (apkg->provided_by->len == 0))
187           return NULL;
188
189      opkg_message(conf, OPKG_DEBUG, "best installation candidate for %s\n", apkg->name);
190
191      provided_apkg_vec = apkg->provided_by;
192      nprovides = provided_apkg_vec->len;
193      provided_apkgs = provided_apkg_vec->pkgs;
194      if (nprovides > 1)
195           opkg_message(conf, OPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides);
196
197      /* accumulate all the providers */
198      for (i = 0; i < nprovides; i++) {
199           abstract_pkg_t *provider_apkg = provided_apkgs[i];
200           opkg_message(conf, OPKG_DEBUG, " adding %s to providers\n", provider_apkg->name);
201           abstract_pkg_vec_insert(providers, provider_apkg);
202      }
203      nprovides = providers->len;
204
205      for (i = 0; i < nprovides; i++) {
206           abstract_pkg_t *provider_apkg = abstract_pkg_vec_get(providers, i);
207           abstract_pkg_t *replacement_apkg = NULL;
208           pkg_vec_t *vec;
209
210           if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) {
211                replacement_apkg = provider_apkg->replaced_by->pkgs[0];
212                if (provider_apkg->replaced_by->len > 1) {
213                     opkg_message(conf, OPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n", 
214                                  provider_apkg->name, replacement_apkg->name);
215                }
216           }
217
218           if (replacement_apkg)
219                opkg_message(conf, OPKG_DEBUG, "   replacement_apkg=%s for provider_apkg=%s\n", 
220                             replacement_apkg->name, provider_apkg->name);
221
222           if (replacement_apkg && (replacement_apkg != provider_apkg)) {
223                if (abstract_pkg_vec_contains(providers, replacement_apkg))
224                     continue;
225                else
226                     provider_apkg = replacement_apkg;
227           }
228
229           if (!(vec = provider_apkg->pkgs)) {
230                opkg_message(conf, OPKG_DEBUG, "   no pkgs for provider_apkg %s\n", provider_apkg->name);
231                continue;
232           }
233     
234
235           /* now check for supported architecture */
236           {
237                int max_count = 0;
238                int i;
239
240                /* count packages matching max arch priority and keep track of last one */
241                for (i = 0; i < vec->len; i++) {
242                     pkg_t *maybe = vec->pkgs[i];
243                     opkg_message(conf, OPKG_DEBUG, "  %s arch=%s arch_priority=%d version=%s  \n",
244                                  maybe->name, maybe->architecture, maybe->arch_priority, maybe->version);
245                     if (maybe->arch_priority > 0)  {
246                          max_count++;
247                          abstract_pkg_vec_insert(matching_apkgs, maybe->parent);
248                          pkg_vec_insert(matching_pkgs, maybe);
249                     }
250                }
251           }
252      }
253
254      if (matching_pkgs->len > 1)
255           pkg_vec_sort(matching_pkgs, pkg_name_version_and_architecture_compare);
256      if (matching_apkgs->len > 1)
257           abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare);
258
259 /* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the
260    needed package. In this case, I would return it for install, otherwise I will continue with the procedure */
261 /* The problem is what to do when there are more than a mathing package, with the same name and several version ?
262    Until now I always got the latest, but that breaks the downgrade option.
263    If I stop at the first one, I would probably miss the new ones 
264    Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file,
265    or from a Packages feed.
266    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*/
267 /*Pigi*/
268
269      for (i = 0; i < matching_pkgs->len; i++) {
270           pkg_t *matching = matching_pkgs->pkgs[i];
271           if (constraint_fcn(matching, cdata)) {  /* We found it */
272              opkg_message(conf, OPKG_DEBUG, " Found a valid candidate for the install: %s %s  \n", matching->name, matching->version) ;
273              good_pkg_by_name = matching;
274              if ( matching->provided_by_hand == 1 )    /* It has been provided by hand, so it is what user want */
275                 break;                                 
276           }
277      }
278
279
280      for (i = 0; i < matching_pkgs->len; i++) {
281           pkg_t *matching = matching_pkgs->pkgs[i];
282           latest_matching = matching;
283           if (matching->parent->state_status == SS_INSTALLED || matching->parent->state_status == SS_UNPACKED)
284                latest_installed_parent = matching;
285           if (matching->state_flag & (SF_HOLD|SF_PREFER)) {
286                if (held_pkg)
287                     opkg_message(conf, OPKG_ERROR, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER.  Using latest.\n",
288                                  held_pkg->name, matching->name);
289                held_pkg = matching;
290           }
291      }
292
293      if (!good_pkg_by_name && !held_pkg && !latest_installed_parent && matching_apkgs->len > 1 && !quiet) {
294           opkg_message(conf, OPKG_ERROR, "Package=%s, %d matching providers\n",
295                        apkg->name, matching_apkgs->len);
296           for (i = 0; i < matching_apkgs->len; i++) {
297               abstract_pkg_t *matching = matching_apkgs->pkgs[i];
298               opkg_message(conf, OPKG_ERROR, "    %s\n", matching->name);
299           }
300           opkg_message(conf, OPKG_ERROR, "Please select one with opkg install or opkg flag prefer\n");
301      }
302
303      if (matching_apkgs->len > 1 && conf->verbosity > 1) {
304           opkg_message(conf, OPKG_NOTICE, "%s: for apkg=%s, %d matching pkgs\n",
305                        __FUNCTION__, apkg->name, matching_pkgs->len);
306           for (i = 0; i < matching_pkgs->len; i++) {
307                pkg_t *matching = matching_pkgs->pkgs[i];
308                opkg_message(conf, OPKG_INFO, "    %s %s %s\n",
309                             matching->name, matching->version, matching->architecture);
310           }
311      }
312
313      nmatching = matching_apkgs->len;
314
315      pkg_vec_free(matching_pkgs);
316      abstract_pkg_vec_free(matching_apkgs);
317      abstract_pkg_vec_free(providers);
318
319      if (good_pkg_by_name) {   /* We found a good candidate, we will install it */ 
320           return good_pkg_by_name;
321      }
322      if (held_pkg) {
323           opkg_message(conf, OPKG_INFO, "  using held package %s\n", held_pkg->name);
324           return held_pkg;
325      }
326      if (latest_installed_parent) {
327           opkg_message(conf, OPKG_INFO, "  using latest version of installed package %s\n", latest_installed_parent->name);
328           return latest_installed_parent;
329      }
330      if (nmatching > 1) {
331           opkg_message(conf, OPKG_INFO, "  no matching pkg out of matching_apkgs=%d\n", nmatching);
332           return NULL;
333      }
334      if (latest_matching) {
335           opkg_message(conf, OPKG_INFO, "  using latest matching %s %s %s\n",
336                        latest_matching->name, latest_matching->version, latest_matching->architecture);
337           return latest_matching;
338      }
339      return NULL;
340 }
341
342 static int pkg_name_constraint_fcn(pkg_t *pkg, void *cdata)
343 {
344      const char *name = (const char *)cdata;
345      if (strcmp(pkg->name, name) == 0)
346           return 1;
347      else
348           return 0;   
349 }
350
351 pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(opkg_conf_t *conf, const char *name)
352 {
353      hash_table_t *hash = &conf->pkg_hash;
354      abstract_pkg_t *apkg = NULL;
355
356      if (!(apkg = abstract_pkg_fetch_by_name(hash, name)))
357           return NULL;
358      
359      return pkg_hash_fetch_best_installation_candidate(conf, apkg, pkg_name_constraint_fcn, apkg->name, 0);
360 }
361
362
363 pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash, 
364                                        const char *pkg_name,
365                                        const char * version)
366 {
367     pkg_vec_t * vec;
368     register int i;
369     char *version_str = NULL;
370     
371     if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name)))
372         return NULL;
373     
374     for(i = 0; i < vec->len; i++) {
375         version_str = pkg_version_str_alloc(vec->pkgs[i]);
376         if(!strcmp(version_str, version)) {
377             free(version_str);
378             break;
379         }
380         free(version_str);
381     }
382         
383     if(i == vec->len)
384         return NULL;
385     
386     return vec->pkgs[i];
387 }
388
389 pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash,
390                                              const char *pkg_name,
391                                              pkg_dest_t *dest)
392 {
393     pkg_vec_t * vec;
394     register int i;
395
396     if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) {
397         return NULL;
398     }
399     
400     for(i = 0; i < vec->len; i++)
401         if((vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED) && vec->pkgs[i]->dest == dest) {
402             return vec->pkgs[i];
403         }
404     return NULL;
405 }
406
407 pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash,
408                                         const char *pkg_name)
409 {
410     pkg_vec_t * vec;
411     register int i;
412
413     if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))){
414         return NULL;
415     } 
416
417     for(i = 0; i < vec->len; i++)
418         if (vec->pkgs[i]->state_status == SS_INSTALLED || vec->pkgs[i]->state_status == SS_UNPACKED){
419             return vec->pkgs[i];
420         } 
421     
422     return NULL;
423 }
424
425 pkg_vec_t *pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name)
426 {
427     abstract_pkg_t * ab_pkg;
428
429     if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))){
430        return NULL;
431     }
432     
433     if (ab_pkg->pkgs) {
434       return ab_pkg->pkgs;
435     } else if (ab_pkg->provided_by) {
436       abstract_pkg_t *abpkg =  abstract_pkg_vec_get(ab_pkg->provided_by, 0);
437       if (abpkg != NULL){
438           return abpkg->pkgs;
439       } else {
440           return ab_pkg->pkgs;
441       }
442     } else {
443       return NULL;
444     }
445 }
446
447 static int pkg_compare_names(const void *p1, const void *p2)
448 {
449   const pkg_t *pkg1 = *(const pkg_t **)p1;
450   const pkg_t *pkg2 = *(const pkg_t **)p2;
451   if (pkg1->name == NULL)
452     return 1;
453   if (pkg2->name == NULL)
454     return -1;
455   return(strcmp(pkg1->name, pkg2->name));
456 }
457
458
459 static void pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data)
460 {
461   int j;
462   abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
463   pkg_vec_t *all = (pkg_vec_t *)data;
464   pkg_vec_t *pkg_vec = ab_pkg->pkgs;
465   if (pkg_vec) {
466     for (j = 0; j < pkg_vec->len; j++) {
467       pkg_t *pkg = pkg_vec->pkgs[j];
468       pkg_vec_insert(all, pkg);
469     }
470   }
471 }
472
473 void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all)
474 {
475     hash_table_foreach(hash, pkg_hash_fetch_available_helper, all);
476     qsort(all->pkgs, all->len, sizeof(pkg_t *), pkg_compare_names);
477 }
478
479 static void pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *data)
480 {
481   abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
482   pkg_vec_t *all = (pkg_vec_t *)data;
483   pkg_vec_t *pkg_vec = ab_pkg->pkgs;
484   int j;
485   if (pkg_vec) {
486     for (j = 0; j < pkg_vec->len; j++) {
487       pkg_t *pkg = pkg_vec->pkgs[j];
488       if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) {
489         pkg_vec_insert(all, pkg);
490       }
491     }
492   }
493 }
494 void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all)
495 {
496     hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all);
497     qsort(all->pkgs, all->len, sizeof(void*), pkg_compare_names);
498 }
499
500 static void pkg_hash_dump_helper(const char *pkg_name, void *entry, void *data)
501 {
502   int i;
503   pkg_t *pkg;
504   abstract_pkg_t *ab_pkg = (abstract_pkg_t *)entry;
505   opkg_conf_t *conf = (opkg_conf_t *)data;
506   abstract_pkg_t ** dependents = ab_pkg->depended_upon_by;
507   fprintf(stdout, "%s\n", ab_pkg->name);
508   i = 0;
509   if (dependents != NULL)
510     while (dependents [i] != NULL)
511       printf ("\tdepended upon by - %s\n", dependents [i ++]->name);
512   dependents = ab_pkg->provided_by->pkgs;
513   i = 0;
514   if (dependents != NULL)
515     while (dependents [i] != NULL && i < ab_pkg->provided_by->len)
516       printf ("\tprovided by - %s\n", dependents [i ++]->name);
517   pkg = pkg_hash_fetch_best_installation_candidate_by_name (conf, ab_pkg->name);
518   if (pkg) {
519     i = 0;
520     while (i < pkg->depends_count)
521       printf ("\tdepends on - %s\n", pkg->depends_str [i ++]);  
522   }
523 }
524 void pkg_hash_dump(hash_table_t *hash, void *data)
525 {
526
527   printf ("\n\n+=+%s+=+\n\n", __FUNCTION__);
528   hash_table_foreach(hash, pkg_hash_dump_helper, data);
529   printf ("\n+=+%s+=+\n\n", __FUNCTION__);    
530 }
531
532 abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name)
533 {
534   abstract_pkg_t * ab_pkg;
535
536   if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name)))
537     ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name);
538
539   return ab_pkg;
540 }
541
542 pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,opkg_conf_t *conf)
543 {
544      abstract_pkg_t * ab_pkg;
545      int arch_priority;
546
547      if(!pkg)
548           return pkg;
549
550      arch_priority = pkg->arch_priority;
551
552      if (buildDepends(hash, pkg)<0){
553         fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
554         return NULL;
555      }
556      ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name);
557
558      if (set_status) {
559           if (pkg->state_status == SS_INSTALLED) {
560                ab_pkg->state_status = SS_INSTALLED;
561           } else if (pkg->state_status == SS_UNPACKED) {
562                ab_pkg->state_status = SS_UNPACKED;
563           }
564      }
565
566      if(!ab_pkg->pkgs)
567           ab_pkg->pkgs = pkg_vec_alloc();
568     
569      /* pkg_vec_insert_merge might munge package, but it returns an unmunged pkg */
570      pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf );
571      pkg->parent = ab_pkg;
572
573      if (buildProvides(hash, ab_pkg, pkg)<0){
574         fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
575         return NULL;
576      }
577      /* need to build the conflicts graph before replaces for correct calculation of replaced_by relation */
578      if (buildConflicts(hash, ab_pkg, pkg)<0){
579         fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
580         return NULL;
581      }
582      if (buildReplaces(hash, ab_pkg, pkg)<0) {
583         fprintf(stderr, "%s : This should never happen. Report this Bug in bugzilla please \n ",__FUNCTION__);
584         return NULL;
585      }
586     
587      buildDependedUponBy(pkg, ab_pkg);
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 = strdup(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           str_list_remove_elt(old_owning_pkg->installed_files, file_name);
636           /* mark this package to have its filelist written */
637           old_owning_pkg->state_flag |= SF_FILELIST_CHANGED;
638           owning_pkg->state_flag |= SF_FILELIST_CHANGED;
639      }
640      return 0;
641 }
642
643