Remove outdated comment regarding an old bug.
[oweals/opkg-lede.git] / libopkg / opkg_conf.c
index d0d0329c14330a7e1f3f9c8bb7db544ced2c4ae7..a145ae7ecade6722b4ffa41df339efb1ee2e63f5 100644 (file)
    General Public License for more details.
 */
 
-#include "includes.h"
-#include "opkg_conf.h"
+#include "config.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <glob.h>
+#include <unistd.h>
 
+#include "opkg_conf.h"
+#include "pkg_vec.h"
+#include "pkg.h"
 #include "xregex.h"
 #include "sprintf_alloc.h"
-#include "args.h"
 #include "opkg_message.h"
 #include "file_util.h"
 #include "opkg_defines.h"
 #include "libbb/libbb.h"
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <glob.h>
-
 static int lock_fd;
 static char *lock_file = NULL;
 
@@ -57,6 +59,7 @@ opkg_option_t options[] = {
          { "no_proxy", OPKG_OPT_TYPE_STRING, &_conf.no_proxy },
          { "test", OPKG_OPT_TYPE_BOOL, &_conf.noaction },
          { "noaction", OPKG_OPT_TYPE_BOOL, &_conf.noaction },
+         { "download_only", OPKG_OPT_TYPE_BOOL, &_conf.download_only },
          { "nodeps", OPKG_OPT_TYPE_BOOL, &_conf.nodeps },
          { "offline_root", OPKG_OPT_TYPE_STRING, &_conf.offline_root },
          { "proxy_passwd", OPKG_OPT_TYPE_STRING, &_conf.proxy_passwd },
@@ -341,7 +344,7 @@ opkg_conf_write_status_files(void)
           dest = (pkg_dest_t *)iter->data;
 
           dest->status_fp = fopen(dest->status_file_name, "w");
-          if (dest->status_fp == NULL) {
+          if (dest->status_fp == NULL && errno != EROFS) {
                opkg_perror(ERROR, "Can't open status file %s",
                     dest->status_file_name);
                ret = -1;
@@ -373,7 +376,7 @@ opkg_conf_write_status_files(void)
 
      list_for_each_entry(iter, &conf->pkg_dest_list.head, node) {
           dest = (pkg_dest_t *)iter->data;
-          if (fclose(dest->status_fp) == EOF) {
+          if (dest->status_fp && fclose(dest->status_fp) == EOF) {
                opkg_perror(ERROR, "Couldn't close %s", dest->status_file_name);
               ret = -1;
           }
@@ -471,9 +474,9 @@ opkg_conf_init(void)
        globfree(&globbuf);
 
        if (conf->offline_root)
-               sprintf_alloc (&lock_file, "%s/%s/lock", conf->offline_root, OPKG_STATE_DIR_PREFIX);
+               sprintf_alloc (&lock_file, "%s/%s", conf->offline_root, OPKGLOCKFILE);
        else
-               sprintf_alloc (&lock_file, "%s/lock", OPKG_STATE_DIR_PREFIX);
+               sprintf_alloc (&lock_file, "%s", OPKGLOCKFILE);
 
        lock_fd = creat(lock_file, S_IRUSR | S_IWUSR | S_IRGRP);
        if (lock_fd == -1) {
@@ -483,7 +486,10 @@ opkg_conf_init(void)
 
        if (lockf(lock_fd, F_TLOCK, (off_t)0) == -1) {
                opkg_perror(ERROR, "Could not lock %s", lock_file);
-               goto err3;
+               if (close(lock_fd) == -1)
+                       opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
+                               lock_fd, lock_file);
+               goto err2;
        }
 
        if (conf->tmp_dir)
@@ -499,7 +505,7 @@ opkg_conf_init(void)
        conf->tmp_dir = mkdtemp(tmp);
        if (conf->tmp_dir == NULL) {
                opkg_perror(ERROR, "Creating temp dir %s failed", tmp);
-               goto err4;
+               goto err3;
        }
 
        pkg_hash_init();
@@ -530,14 +536,14 @@ opkg_conf_init(void)
        }
 
        if (resolve_pkg_dest_list(&tmp_dest_nv_pair_list))
-               goto err5;
+               goto err4;
 
        nv_pair_list_deinit(&tmp_dest_nv_pair_list);
 
        return 0;
 
 
-err5:
+err4:
        free(conf->lists_dir);
 
        pkg_hash_deinit();
@@ -546,10 +552,10 @@ err5:
 
        if (rmdir(conf->tmp_dir) == -1)
                opkg_perror(ERROR, "Couldn't remove dir %s", conf->tmp_dir);
-err4:
+err3:
        if (lockf(lock_fd, F_ULOCK, (off_t)0) == -1)
                opkg_perror(ERROR, "Couldn't unlock %s", lock_file);
-err3:
+
        if (close(lock_fd) == -1)
                opkg_perror(ERROR, "Couldn't close descriptor %d (%s)",
                                lock_fd, lock_file);