introduce the active_list for searching.
[project/opkg-lede.git] / libopkg / pkg.c
index 4bbecb9685eb707807cac8540529ab29d0c27984..dde3a19f22ad5ea83ec98eaed425af2ecf3df647 100644 (file)
@@ -77,7 +77,7 @@ pkg_t *pkg_new(void)
 {
      pkg_t *pkg;
 
-     pkg = malloc(sizeof(pkg_t));
+     pkg = calloc(1, sizeof(pkg_t));
      if (pkg == NULL) {
          fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
          return NULL;
@@ -90,7 +90,6 @@ pkg_t *pkg_new(void)
 
 int pkg_init(pkg_t *pkg)
 {
-     memset(pkg, 0, sizeof(pkg_t));
      pkg->name = NULL;
      pkg->epoch = 0;
      pkg->version = NULL;
@@ -112,6 +111,9 @@ int pkg_init(pkg_t *pkg)
      pkg->recommends_str = NULL;
      pkg->suggests_count = 0;
      pkg->recommends_count = 0;
+     
+     active_list_init(&pkg->list);
+     active_list_init(&pkg->searched_node);
 
      /* Abhaya: added init for conflicts fields */
      pkg->conflicts = NULL;
@@ -183,7 +185,8 @@ void pkg_deinit(pkg_t *pkg)
      pkg->state_flag = SF_OK;
      pkg->state_status = SS_NOT_INSTALLED;
 
-     //for (i = 0; i < pkg->replaces_count; i++)
+     active_list_clear(&pkg->list);
+
      free (pkg->replaces);
      pkg->replaces = NULL;
 
@@ -429,7 +432,7 @@ abstract_pkg_t *abstract_pkg_new(void)
 {
      abstract_pkg_t * ab_pkg;
 
-     ab_pkg = malloc(sizeof(abstract_pkg_t));
+     ab_pkg = calloc(1, sizeof(abstract_pkg_t));
 
      if (ab_pkg == NULL) {
          fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
@@ -444,14 +447,13 @@ abstract_pkg_t *abstract_pkg_new(void)
 
 int abstract_pkg_init(abstract_pkg_t *ab_pkg)
 {
-     memset(ab_pkg, 0, sizeof(abstract_pkg_t));
-
      ab_pkg->provided_by = abstract_pkg_vec_alloc();
      if (ab_pkg->provided_by==NULL){
         return -1;
      }
      ab_pkg->dependencies_checked = 0;
      ab_pkg->state_status = SS_NOT_INSTALLED;
+     active_list_init(&ab_pkg->searched_node);
 
      return 0;
 }
@@ -461,7 +463,7 @@ void set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg){
      char **raw =NULL;
      char **raw_start=NULL; 
 
-     temp_str = (char *) malloc (strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
+     temp_str = (char *) calloc (1, strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
      if (temp_str == NULL ){
         opkg_message(conf, OPKG_INFO, "Out of memory in  %s\n", __FUNCTION__);
         return;
@@ -497,7 +499,7 @@ char * pkg_formatted_info(pkg_t *pkg )
      char *line;
      char * buff;
 
-     buff = malloc(8192);
+     buff = calloc(1, 8192);
      if (buff == NULL) {
          fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
          return NULL;
@@ -1313,7 +1315,7 @@ str_list_t *pkg_get_installed_files(pkg_t *pkg)
          return NULL;
      }
 
-     /* For uninstalled packages, get the file list firectly from the package.
+     /* For uninstalled packages, get the file list directly from the package.
        For installed packages, look at the package.list file in the database.
      */
      if (pkg->state_status == SS_NOT_INSTALLED || pkg->dest == NULL) {
@@ -1398,9 +1400,9 @@ int pkg_free_installed_files(pkg_t *pkg)
      str_list_elt_t *iter;
 
      pkg->installed_files_ref_cnt--;
-     if (pkg->installed_files_ref_cnt > 0) {
+
+     if (pkg->installed_files_ref_cnt > 0)
          return 0;
-     }
 
      if (pkg->installed_files) {
 
@@ -1808,6 +1810,8 @@ int pkg_write_filelist(opkg_conf_t *conf, pkg_t *pkg)
      fclose(data.stream);
      free(list_file_name);
 
+     pkg->state_flag &= ~SF_FILELIST_CHANGED;
+
      return err;
 }