Fix pkg_get_installed_files() to work with an offline_root + dest.
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 16 Nov 2009 05:29:13 +0000 (05:29 +0000)
committergraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 16 Nov 2009 05:29:13 +0000 (05:29 +0000)
git-svn-id: http://opkg.googlecode.com/svn/trunk@318 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

libopkg/opkg_cmd.c
libopkg/opkg_install.c
libopkg/opkg_remove.c
libopkg/pkg.c
libopkg/pkg.h
libopkg/pkg_hash.c

index c40694eff8bb1b78425ea5b0f7bf43b6f4c65760..b86e670043daeaef8491b85a0df58dcec64b66e9 100644 (file)
@@ -1028,7 +1028,7 @@ static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv)
          return 0;
      }
 
-     files = pkg_get_installed_files(pkg);
+     files = pkg_get_installed_files(conf, pkg);
      pkg_version = pkg_version_str_alloc(pkg);
 
      printf("Package %s (%s) is installed on %s and has the following files:\n",
@@ -1323,7 +1323,7 @@ static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv)
      for (i=0; i < installed->len; i++) {
          pkg = installed->pkgs[i];
 
-         installed_files = pkg_get_installed_files(pkg);
+         installed_files = pkg_get_installed_files(conf, pkg);
 
          for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) {
               installed_file = (char *)iter->data;
index b57c10e3883b8aceb2b71521848b527381d30b27..834916db997980d8a899e30b4c63a90f3b8bf415 100644 (file)
@@ -427,7 +427,7 @@ static int check_conflicts_for(opkg_conf_t *conf, pkg_t *pkg)
 
 static int update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg)
 {
-     str_list_t *new_list = pkg_get_installed_files(new_pkg);
+     str_list_t *new_list = pkg_get_installed_files(conf, new_pkg);
      str_list_elt_t *iter, *niter;
 
      for (iter = str_list_first(new_list), niter = str_list_next(new_list, iter); 
@@ -441,7 +441,7 @@ static int update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_p
               file_hash_set_file_owner(conf, new_file, new_pkg);
      }
      if (old_pkg) {
-         str_list_t *old_list = pkg_get_installed_files(old_pkg);
+         str_list_t *old_list = pkg_get_installed_files(conf, old_pkg);
          for (iter = str_list_first(old_list), niter = str_list_next(old_list, iter); 
                   iter; 
                   iter = niter, niter = str_list_next(old_list, niter)) {
@@ -1223,7 +1223,7 @@ static int check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
 
      int clashes = 0;
 
-     files_list = pkg_get_installed_files(pkg);
+     files_list = pkg_get_installed_files(conf, pkg);
      for (iter = str_list_first(files_list), niter = str_list_next(files_list, iter); 
              iter; 
              iter = niter, niter = str_list_next(files_list, iter)) {
@@ -1314,7 +1314,7 @@ static int check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *
 
      int clashes = 0;
 
-     files_list = pkg_get_installed_files(pkg);
+     files_list = pkg_get_installed_files(conf, pkg);
      for (iter = str_list_first(files_list), niter = str_list_next(files_list, iter); 
              iter; 
              iter = niter, niter = str_list_next(files_list, niter)) {
@@ -1398,8 +1398,8 @@ static int remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
          return 0;
      }
 
-     old_files = pkg_get_installed_files(old_pkg);
-     new_files = pkg_get_installed_files(pkg);
+     old_files = pkg_get_installed_files(conf, old_pkg);
+     new_files = pkg_get_installed_files(conf, pkg);
 
      new_files_table.entries = NULL;
      hash_table_init("new_files" , &new_files_table, 20);
index eb037146a4715b6da3a966d4377e664c2cb69abd..aadfa6aa6d4b9925775b978fba780fbf9c36d4f3 100644 (file)
@@ -334,13 +334,14 @@ int remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
      conffile_t *conffile;
      int removed_a_dir;
      pkg_t *owner;
-     int rootdirlen;
+     int rootdirlen = 0;
 
      str_list_init(&installed_dirs);
-     installed_files = pkg_get_installed_files(pkg);
+     installed_files = pkg_get_installed_files(conf, pkg);
 
      /* don't include trailing slash */
-     rootdirlen = strlen(pkg->dest->root_dir) -1;
+     if (conf->offline_root)
+          rootdirlen = strlen(conf->offline_root);
 
      for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) {
          file_name = (char *)iter->data;
index 1802ff0f5f2bd41736a583ad7a3f22591f44234d..78b6cadba1abef5c032fc5e15ea2b2a72df8737a 100644 (file)
@@ -969,14 +969,14 @@ pkg_version_str_alloc(pkg_t *pkg)
        return version;
 }
 
-str_list_t *pkg_get_installed_files(pkg_t *pkg)
+str_list_t *pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg)
 {
      int err;
      char *list_file_name = NULL;
      FILE *list_file = NULL;
      char *line;
      char *installed_file_name;
-     int rootdirlen;
+     int rootdirlen = 0;
 
      pkg->installed_files_ref_cnt++;
 
@@ -1024,7 +1024,9 @@ str_list_t *pkg_get_installed_files(pkg_t *pkg)
          free(list_file_name);
      }
 
-     rootdirlen = strlen( pkg->dest->root_dir );
+     if (conf->offline_root)
+          rootdirlen = strlen(conf->offline_root);
+
      while (1) {
          char *file_name;
        
@@ -1035,22 +1037,24 @@ str_list_t *pkg_get_installed_files(pkg_t *pkg)
          str_chomp(line);
          file_name = line;
 
-         /* Take pains to avoid uglies like "/./" in the middle of file_name. */
-         if( strncmp( pkg->dest->root_dir, 
-                      file_name, 
-                      rootdirlen ) ) {
+         if (pkg->state_status == SS_NOT_INSTALLED) {
               if (*file_name == '.') {
                    file_name++;
               }
               if (*file_name == '/') {
                    file_name++;
               }
-
-              /* Freed in pkg_free_installed_files */
-              sprintf_alloc(&installed_file_name, "%s%s", pkg->dest->root_dir, file_name);
+              sprintf_alloc(&installed_file_name, "%s%s",
+                              pkg->dest->root_dir, file_name);
          } else {
-              // already contains root_dir as header -> ABSOLUTE
-              sprintf_alloc(&installed_file_name, "%s", file_name);
+              if (conf->offline_root &&
+                      strncmp(conf->offline_root, file_name, rootdirlen)) {
+                   sprintf_alloc(&installed_file_name, "%s%s",
+                                   conf->offline_root, file_name);
+              } else {
+                   // already contains root_dir as header -> ABSOLUTE
+                   sprintf_alloc(&installed_file_name, "%s", file_name);
+              }
          }
          str_list_append(pkg->installed_files, installed_file_name);
           free(installed_file_name);
@@ -1394,7 +1398,7 @@ int pkg_info_preinstall_check(opkg_conf_t *conf)
      pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs);
      for (i = 0; i < installed_pkgs->len; i++) {
          pkg_t *pkg = installed_pkgs->pkgs[i];
-         str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
+         str_list_t *installed_files = pkg_get_installed_files(conf, pkg); /* this causes installed_files to be cached */
          str_list_elt_t *iter, *niter;
          if (installed_files == NULL) {
               opkg_message(conf, OPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
index d95eed39bc6842ae16f5bd06bfb53e54ef378dba..2e25443ff1bfb7d4968236e77a13b6a245a882b9 100644 (file)
@@ -212,7 +212,7 @@ void pkg_formatted_field(FILE *fp, pkg_t *pkg, const char *field);
 void set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg);
 
 void pkg_print_status(pkg_t * pkg, FILE * file);
-str_list_t *pkg_get_installed_files(pkg_t *pkg);
+str_list_t *pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg);
 int pkg_free_installed_files(pkg_t *pkg);
 int pkg_remove_installed_files_list(opkg_conf_t *conf, pkg_t *pkg);
 conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name);
index 38e3455017ac8fa7f5931eddd782a33bf593a738..ace26bf0cbcc90eceafe2effcc72952c6b228899 100644 (file)
@@ -644,7 +644,7 @@ int file_hash_set_file_owner(opkg_conf_t *conf, const char *file_name, pkg_t *ow
      // opkg_message(conf, OPKG_DEBUG2, "owning_pkg=%s filename=%s\n", owning_pkg->name, file_name);
      hash_table_insert(file_hash, file_name, owning_pkg); 
      if (old_owning_pkg) {
-         pkg_get_installed_files(old_owning_pkg);
+         pkg_get_installed_files(conf, old_owning_pkg);
          str_list_remove_elt(old_owning_pkg->installed_files, file_name);
          pkg_free_installed_files(old_owning_pkg);
          /* mark this package to have its filelist written */