Changeset 4614


Ignore:
Timestamp:
08/27/08 17:39:42 (5 years ago)
Author:
tick
Message:

[opkg] Remove the orphan packages while upgrading

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/opkg/libopkg/opkg_install.c

    r4605 r4614  
    628628} 
    629629 
     630static int pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg)  
     631{ 
     632    int i, j, found; 
     633    char *buf, *d_str; 
     634    pkg_t *p; 
     635    if (!old_pkg)  
     636        return 0; 
     637    if (!pkg) { 
     638        fprintf(stderr, "pkg shall not be NULL here.  please send to the bugzilla!! [%s %d]\n", __FILE__, __LINE__); 
     639        return -1; 
     640    } 
     641    if (old_pkg->depends_count == 0)  
     642        return 0; 
     643    for (i=0;i<old_pkg->depends_count;i++) { 
     644        found = 0; 
     645        for (j=0;j<pkg->depends_count;j++) { 
     646            if (!strcmp(old_pkg->depends_str[i], pkg->depends_str[j])) { 
     647                found = 1; 
     648                break; 
     649            } 
     650        } 
     651        if (found) 
     652            continue; 
     653        d_str = old_pkg->depends_str[i]; 
     654        buf = malloc (strlen (d_str) + 1); 
     655        j=0; 
     656        while (d_str[j] != '\0' && d_str[j] != ' ') { 
     657            buf[j]=d_str[j]; 
     658            ++j; 
     659        } 
     660        buf[j]='\0'; 
     661        buf = realloc (buf, strlen (buf) + 1); 
     662        p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash, buf); 
     663        if (!p) { 
     664            fprintf(stderr, "The pkg %s had been removed!!\n", buf); 
     665            free(buf); 
     666            continue; 
     667        } 
     668        if (p->auto_installed) { 
     669            int deps; 
     670            abstract_pkg_t **dependents; 
     671            deps = pkg_has_installed_dependents(conf, NULL, p, &dependents); 
     672            if (deps == 0) { 
     673                opkg_message (conf, OPKG_NOTICE,"%s was autoinstalled but is now orphaned, remove it.\n", buf); 
     674                opkg_remove_pkg(conf, p, 0); 
     675            } else  
     676                opkg_message (conf, OPKG_INFO, "%s was autoinstalled and is still required by %d installed packages\n", buf, deps); 
     677        } 
     678        free(buf); 
     679    } 
     680    return 0; 
     681} 
     682 
    630683/* returns number of installed replacees */ 
    631684int pkg_get_installed_replacees(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees) 
     
    909962          pkg->state_flag |= SF_FILELIST_CHANGED; 
    910963 
     964          pkg_remove_orphan_dependent(conf, pkg, old_pkg); 
     965 
    911966          /* XXX: BUG: we really should treat replacement more like an upgrade 
    912967           *      Instead, we're going to remove the replacees  
Note: See TracChangeset for help on using the changeset viewer.