opkg: use a single temporary directory for entire update transaction and remove
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 04:52:54 +0000 (04:52 +0000)
committerticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 04:52:54 +0000 (04:52 +0000)
it when done.

git-svn-id: http://opkg.googlecode.com/svn/trunk@46 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

libopkg/opkg_cmd.c

index db04a4a680fbd8ace0e114bfa681febf8d01d9eb..27765f3ac7efde012f11f8b9a1703db717df78f4 100644 (file)
@@ -184,6 +184,7 @@ int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, const char **arg
 
 static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
 {
+     char *tmp;
      int err;
      int failures;
      char *lists_dir;
@@ -212,6 +213,16 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
      } 
 
      failures = 0;
+
+
+     tmp = strdup ("/tmp/opkg.XXXXXX");
+
+     if (mkdtemp (tmp) == NULL) {
+        perror ("mkdtemp");
+        failures++;
+     }
+
+
      for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
          char *url, *list_file_name;
 
@@ -225,17 +236,8 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
 
          sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
          if (src->gzip) {
-             char *tmp;
              char *tmp_file_name;
              FILE *in, *out;
-
-             tmp = strdup ("/tmp/opkg.XXXXXX");
-
-             if (mkdtemp (tmp) == NULL) {
-                 perror ("mkdtemp");
-                 failures++;
-                 continue;
-             }
              
              sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
              err = opkg_download(conf, url, tmp_file_name);
@@ -252,8 +254,6 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
                   if (out)
                        fclose (out);
                   unlink (tmp_file_name);
-                  rmdir (tmp);
-                  free (tmp);
              }
          } else
              err = opkg_download(conf, url, list_file_name);
@@ -274,14 +274,9 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
          else
              sprintf_alloc(&url, "%s/%s", src->value, "Packages.sig");
 
-         /* create temporary dir for it */
-         char *tmp, *tmp_file_name;
-         tmp = strdup ("/tmp/opkg.XXXXXX");
-         if (mkdtemp (tmp) == NULL) {
-               perror ("mkdtemp");
-               failures++;
-               continue;
-         }
+         /* create temporary file for it */
+         char *tmp_file_name;
+
          sprintf_alloc (&tmp_file_name, "%s/%s", tmp, "Packages.sig");
 
          err = opkg_download(conf, url, tmp_file_name);
@@ -297,12 +292,13 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
                opkg_message (conf, OPKG_NOTICE, "Signature check failed\n");
          }
          unlink (tmp_file_name);
-         unlink (tmp);
          free (tmp_file_name);
 
          free (url);
          free(list_file_name);
      }
+     rmdir (tmp);
+     free (tmp);
      free(lists_dir);
 
 #ifdef CONFIG_CLEAR_SW_INSTALL_FLAG