Changeset 4425


Ignore:
Timestamp:
05/12/08 15:48:41 (5 years ago)
Author:
thomas
Message:

opkg: download required packages before install and report progress to clients

File:
1 edited

Legend:

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

    r4419 r4425  
    360360{ 
    361361  int err; 
    362   char *package_id = NULL; 
     362  char *package_id = NULL, *stripped_filename; 
    363363  opkg_progress_data_t pdata; 
    364   pkg_t *new; 
     364  pkg_t *old, *new; 
     365  pkg_vec_t *deps, *all; 
     366  int i, ndepends; 
     367  char **unresolved = NULL; 
    365368 
    366369  opkg_assert (opkg != NULL); 
     
    370373  pkg_info_preinstall_check (opkg->conf); 
    371374 
    372   new = pkg_hash_fetch_best_installation_candidate_by_name (opkg->conf, package_name); 
    373  
     375 
     376  /* check to ensure package is not already installed */ 
     377  old = pkg_hash_fetch_installed_by_name(&opkg->conf->pkg_hash, package_name); 
     378  if (old) 
     379  { 
     380    /* XXX: Error: Package is already installed. */ 
     381    return 1; 
     382  } 
     383 
     384  new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, package_name); 
    374385  if (!new) 
    375386  { 
     
    377388    return 1; 
    378389  } 
     390 
     391  new->state_flag |= SF_USER; 
     392 
    379393  pdata.action = OPKG_INSTALL; 
    380394  pdata.package = old_pkg_to_new (new); 
     
    382396  progress (pdata, 0); 
    383397 
    384   /* download the package */ 
    385   opkg_prepare_url_for_install (opkg->conf, package_name, &package_id); 
    386  
    387   progress (pdata, 50); 
     398  /* find dependancies and download them */ 
     399  deps = pkg_vec_alloc (); 
     400  /* this function does not return the original package, so we insert it later */ 
     401  ndepends = pkg_hash_fetch_unsatisfied_dependencies (opkg->conf, new, deps, &unresolved); 
     402  if (unresolved) 
     403  { 
     404    /* XXX: Error: Could not satisfy dependencies */ 
     405    pkg_vec_free (deps); 
     406    return 1; 
     407  } 
     408 
     409  /* insert the package we are installing so that we download it */ 
     410  pkg_vec_insert (deps, new); 
     411 
     412  /* download package and dependancies */ 
     413  for (i = 0; i < deps->len; i++) 
     414  { 
     415    pkg_t *pkg; 
     416    struct _curl_cb_data cb_data; 
     417    char *url; 
     418 
     419    pkg = deps->pkgs[i]; 
     420    if (pkg->local_filename) 
     421      continue; 
     422 
     423    opkg_package_free (pdata.package); 
     424    pdata.package = old_pkg_to_new (pkg); 
     425    pdata.action = OPKG_DOWNLOAD; 
     426 
     427    if (pkg->src == NULL) 
     428    { 
     429      /* XXX: Error: Package not available from any configured src */ 
     430      return 1; 
     431    } 
     432 
     433    sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename); 
     434 
     435    /* Get the filename part, without any directory */ 
     436    stripped_filename = strrchr(pkg->filename, '/'); 
     437    if ( ! stripped_filename ) 
     438        stripped_filename = pkg->filename; 
     439 
     440    sprintf_alloc(&pkg->local_filename, "%s/%s", opkg->conf->tmp_dir, stripped_filename); 
     441 
     442    cb_data.cb = progress_callback; 
     443    cb_data.progress_data = &pdata; 
     444    cb_data.opkg = opkg; 
     445    cb_data.user_data = user_data; 
     446    /* 75% of "install" progress is for downloading */ 
     447    cb_data.start_range = 75 * i / deps->len; 
     448    cb_data.finish_range = 75 * (i + 1) / deps->len; 
     449 
     450    err = opkg_download(opkg->conf, url, pkg->local_filename, 
     451              (curl_progress_func) curl_progress_cb, &cb_data); 
     452    free(url); 
     453 
     454  } 
     455  pkg_vec_free (deps); 
     456 
     457  /* clear depenacy checked marks, left by pkg_hash_fetch_unsatisfied_dependencies */ 
     458  all = pkg_vec_alloc (); 
     459  pkg_hash_fetch_available (&opkg->conf->pkg_hash, all); 
     460  for (i = 0; i < all->len; i++) 
     461  { 
     462    all->pkgs[i]->parent->dependencies_checked = 0; 
     463  } 
     464  pkg_vec_free (all); 
     465 
     466 
     467  /* 75% of "install" progress is for downloading */ 
     468  opkg_package_free (pdata.package); 
     469  pdata.package = old_pkg_to_new (new); 
     470  pdata.action = OPKG_INSTALL; 
     471  progress (pdata, 75); 
    388472 
    389473  if (!package_id) 
     
    391475 
    392476  /* unpack the package */ 
    393   if (opkg->conf->multiple_providers) 
    394   { 
    395     err = opkg_install_multi_by_name (opkg->conf, package_id); 
    396   } 
    397   else 
    398   { 
    399     err = opkg_install_by_name (opkg->conf, package_id); 
    400   } 
     477  err = opkg_install_pkg(opkg->conf, new, 0); 
    401478 
    402479  if (err) 
Note: See TracChangeset for help on using the changeset viewer.