LCOV - code coverage report
Current view: top level - libpkg/private - pkg_jobs.h (source / functions) Hit Total Coverage
Test: cov.info Lines: 1 1 100.0 %
Date: 2015-08-15 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* Copyright (c) 2014, Vsevolod Stakhov
       2             :  * All rights reserved.
       3             :  *
       4             :  * Redistribution and use in source and binary forms, with or without
       5             :  * modification, are permitted provided that the following conditions are met:
       6             :  *       * Redistributions of source code must retain the above copyright
       7             :  *         notice, this list of conditions and the following disclaimer.
       8             :  *       * Redistributions in binary form must reproduce the above copyright
       9             :  *         notice, this list of conditions and the following disclaimer in the
      10             :  *         documentation and/or other materials provided with the distribution.
      11             :  *
      12             :  * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
      13             :  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
      14             :  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      15             :  * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
      16             :  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
      17             :  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      18             :  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
      19             :  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      20             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
      21             :  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      22             :  */
      23             : #ifndef PKG_JOBS_H_
      24             : #define PKG_JOBS_H_
      25             : 
      26             : #include <sys/cdefs.h>
      27             : #include <sys/sbuf.h>
      28             : #include <sys/types.h>
      29             : 
      30             : #include <stdbool.h>
      31             : #include <uthash.h>
      32             : #include <utlist.h>
      33             : #include <ucl.h>
      34             : 
      35             : #include "private/utils.h"
      36             : #include "private/pkg.h"
      37             : #include "pkg.h"
      38             : #include "tree.h"
      39             : 
      40             : struct pkg_jobs;
      41             : struct job_pattern;
      42             : 
      43             : struct pkg_job_universe_item {
      44             :         struct pkg *pkg;
      45             :         int priority;
      46             :         bool processed;
      47             :         UT_hash_handle hh;
      48             :         struct pkg_job_universe_item *next, *prev;
      49             : };
      50             : 
      51             : struct pkg_job_request_item {
      52             :         struct pkg *pkg;
      53             :         struct pkg_job_universe_item *unit;
      54             :         struct job_pattern *jp;
      55             :         struct pkg_job_request_item *prev, *next;
      56             : };
      57             : 
      58             : struct pkg_job_request {
      59             :         struct pkg_job_request_item *item;
      60             :         bool skip;
      61             :         bool automatic;
      62             :         UT_hash_handle hh;
      63             : };
      64             : 
      65             : struct pkg_solved {
      66             :         struct pkg_job_universe_item *items[2];
      67             :         pkg_solved_t type;
      68             :         bool already_deleted;
      69             :         struct pkg_solved *prev, *next;
      70             : };
      71             : 
      72         144 : KHASH_MAP_INIT_STR(pkg_jobs_seen, struct pkg_job_universe_item *);
      73             : 
      74             : struct pkg_job_provide {
      75             :         struct pkg_job_universe_item *un;
      76             :         const char *provide;
      77             :         bool is_shlib;
      78             :         struct pkg_job_provide *next, *prev;
      79             :         UT_hash_handle hh;
      80             : };
      81             : 
      82             : struct pkg_job_replace {
      83             :         char *new_uid;
      84             :         char *old_uid;
      85             :         struct pkg_job_replace *next;
      86             : };
      87             : 
      88             : struct pkg_jobs_universe {
      89             :         struct pkg_job_universe_item *items;
      90             :         kh_pkg_jobs_seen_t *seen;
      91             :         struct pkg_job_provide *provides;
      92             :         struct pkg_job_replace *uid_replaces;
      93             :         struct pkg_jobs *j;
      94             :         size_t nitems;
      95             : };
      96             : 
      97             : struct pkg_jobs_conflict_item {
      98             :         uint64_t hash;
      99             :         struct pkg_job_universe_item *item;
     100             :         TREE_ENTRY(pkg_jobs_conflict_item) entry;
     101             : };
     102             : 
     103             : struct pkg_jobs {
     104             :         struct pkg_jobs_universe *universe;
     105             :         struct pkg_job_request  *request_add;
     106             :         struct pkg_job_request  *request_delete;
     107             :         struct pkg_solved *jobs;
     108             :         struct pkgdb    *db;
     109             :         pkg_jobs_t       type;
     110             :         pkg_flags        flags;
     111             :         int              solved;
     112             :         int count;
     113             :         int total;
     114             :         int conflicts_registered;
     115             :         bool need_fetch;
     116             :         const char *reponame;
     117             :         const char *destdir;
     118             :         TREE_HEAD(, pkg_jobs_conflict_item) *conflict_items;
     119             :         struct job_pattern *patterns;
     120             : };
     121             : 
     122             : struct job_pattern {
     123             :         char            *pattern;
     124             :         char            *path;
     125             :         match_t         match;
     126             :         bool            is_file;
     127             :         UT_hash_handle hh;
     128             : };
     129             : 
     130             : enum pkg_priority_update_type {
     131             :         PKG_PRIORITY_UPDATE_REQUEST = 0,
     132             :         PKG_PRIORITY_UPDATE_UNIVERSE,
     133             :         PKG_PRIORITY_UPDATE_CONFLICT,
     134             :         PKG_PRIORITY_UPDATE_DELETE
     135             : };
     136             : 
     137             : /*
     138             :  * Update priorities for all items related with the specified item
     139             :  */
     140             : void pkg_jobs_update_universe_priority(struct pkg_jobs_universe *universe,
     141             :         struct pkg_job_universe_item *it, enum pkg_priority_update_type type);
     142             : /*
     143             :  * Update priority as the conflict was found
     144             :  */
     145             : void pkg_jobs_update_conflict_priority(struct pkg_jobs_universe *universe,
     146             :         struct pkg_solved *req);
     147             : 
     148             : /*
     149             :  * Free universe
     150             :  */
     151             : void pkg_jobs_universe_free(struct pkg_jobs_universe *universe);
     152             : 
     153             : /*
     154             :  * Create universe for jobs
     155             :  */
     156             : struct pkg_jobs_universe * pkg_jobs_universe_new(struct pkg_jobs *j);
     157             : 
     158             : /*
     159             :  * Add a package to the universe
     160             :  */
     161             : int pkg_jobs_universe_process(struct pkg_jobs_universe *universe,
     162             :         struct pkg *pkg);
     163             : 
     164             : /*
     165             :  * Add a package to the universe and store resulting item in `result`
     166             :  */
     167             : int pkg_jobs_universe_process_item(struct pkg_jobs_universe *universe,
     168             :         struct pkg *pkg, struct pkg_job_universe_item **result);
     169             : 
     170             : /*
     171             :  * Search for an entry corresponding to the uid in the universe
     172             :  */
     173             : struct pkg_job_universe_item* pkg_jobs_universe_find(struct pkg_jobs_universe
     174             :         *universe, const char *uid);
     175             : 
     176             : /*
     177             :  * Add a single package to the universe
     178             :  */
     179             : int pkg_jobs_universe_add_pkg(struct pkg_jobs_universe *universe,
     180             :         struct pkg *pkg, bool force, struct pkg_job_universe_item **found);
     181             : 
     182             : /*
     183             :  * Change uid for universe item
     184             :  */
     185             : void pkg_jobs_universe_change_uid(struct pkg_jobs_universe *universe,
     186             :         struct pkg_job_universe_item *unit,
     187             :         const char *new_uid, size_t uidlen, bool update_rdeps);
     188             : 
     189             : 
     190             : 
     191             : /*
     192             :  * Find local package in db or universe
     193             :  */
     194             : struct pkg* pkg_jobs_universe_get_local(struct pkg_jobs_universe *universe,
     195             :         const char *uid, unsigned flag);
     196             : 
     197             : /*
     198             :  * Resolve conflicts in request
     199             :  */
     200             : int pkg_conflicts_request_resolve(struct pkg_jobs *j);
     201             : 
     202             : /*
     203             :  * Append conflicts to a package
     204             :  */
     205             : int pkg_conflicts_append_chain(struct pkg_job_universe_item *it,
     206             :         struct pkg_jobs *j);
     207             : /*
     208             :  * Perform integrity check for the jobs specified
     209             :  */
     210             : int pkg_conflicts_integrity_check(struct pkg_jobs *j);
     211             : /*
     212             :  * Register a conflict between two packages
     213             :  */
     214             : void pkg_conflicts_register(struct pkg *p1, struct pkg *p2,
     215             :                 enum pkg_conflict_type type);
     216             : 
     217             : /*
     218             :  * Check whether `rp` is an upgrade for `lp`
     219             :  */
     220             : bool pkg_jobs_need_upgrade(struct pkg *rp, struct pkg *lp);
     221             : 
     222             : /*
     223             :  * Pre-process universe to fix complex upgrade chains
     224             :  */
     225             : void pkg_jobs_universe_process_upgrade_chains(struct pkg_jobs *j);
     226             : 
     227             : /*
     228             :  * Find upgrade candidates for a specified local package `lp`
     229             :  * This function updates universe as following:
     230             :  * - if `lp` is not null it is always added to the universe
     231             :  * - if `uid` is in the universe, then the existing upgrade chain is returned
     232             :  * - if `force` is true then all candidates are added to the universe
     233             :  * - if `forece` is false then *all* candidates are added to the universe, but
     234             :  * merely if *any* of remote packages is an upgrade for local one
     235             :  */
     236             : struct pkg_job_universe_item*
     237             : pkg_jobs_universe_get_upgrade_candidates(struct pkg_jobs_universe *universe,
     238             :         const char *uid, struct pkg *lp, bool force);
     239             : 
     240             : /*
     241             :  * Among a set of job candidates, select the most matching one, depending on job
     242             :  * type, repos priorities and other stuff
     243             :  */
     244             : struct pkg_job_universe_item *
     245             : pkg_jobs_universe_select_candidate(struct pkg_job_universe_item *chain,
     246             :         struct pkg_job_universe_item *local, bool conservative);
     247             : 
     248             : /*
     249             :  * Free job request (with all candidates)
     250             :  */
     251             : void pkg_jobs_request_free(struct pkg_job_request *req);
     252             : 
     253             : #endif /* PKG_JOBS_H_ */

Generated by: LCOV version 1.10