aboutsummaryrefslogtreecommitdiffstats
path: root/src/transaction.h
blob: c1890e4d5e7c1d7ef2c73f3bb68d6e3016f03288 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright (C) 2003-2020 Jason Woodward <woodwardj at jaos dot org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/*
  this defines the max length of the transaction summary lines, hopefully
  someday this will be replaced with a more dynamic solution.
*/
#define MAX_LINE_LEN 80

enum slapt_action {
    SLAPT_ACTION_USAGE = 0,
    SLAPT_ACTION_UPDATE,
    SLAPT_ACTION_INSTALL,
    SLAPT_ACTION_REMOVE,
    SLAPT_ACTION_SHOW,
    SLAPT_ACTION_SEARCH,
    SLAPT_ACTION_UPGRADE,
    SLAPT_ACTION_LIST,
    SLAPT_ACTION_INSTALLED,
    SLAPT_ACTION_CLEAN,
    SLAPT_ACTION_SHOWVERSION,
    SLAPT_ACTION_AUTOCLEAN,
    SLAPT_ACTION_AVAILABLE,
    SLAPT_ACTION_INSTALL_DISK_SET,
    SLAPT_ACTION_FILELIST,
#ifdef SLAPT_HAS_GPGME
    SLAPT_ACTION_ADD_KEYS,
#endif
    SLAPT_ACTION_END
};

typedef struct {
    union {
        slapt_pkg_t *i;
        slapt_pkg_upgrade_t *u;
    } pkg;
    enum slapt_action type;
} slapt_queue_i;
slapt_queue_i *slapt_queue_i_init(slapt_pkg_t *, slapt_pkg_upgrade_t *);
void slapt_queue_i_free(slapt_queue_i *);

typedef struct {
    slapt_vector_t *install_pkgs;
    slapt_vector_t *upgrade_pkgs;
    slapt_vector_t *reinstall_pkgs;
    slapt_vector_t *remove_pkgs;
    slapt_vector_t *exclude_pkgs;
    slapt_vector_t *suggests;
    slapt_vector_t *conflict_err;
    slapt_vector_t *missing_err;
    slapt_vector_t *queue;
} slapt_transaction_t;

/* fill in transaction structure with defaults */
slapt_transaction_t *slapt_init_transaction(void);
/* download and install/remove/upgrade packages as defined in the transaction, returns 0 on success */
int slapt_handle_transaction(const slapt_config_t *, slapt_transaction_t *);

/* add package for installation to transaction */
void slapt_add_install_to_transaction(slapt_transaction_t *, slapt_pkg_t *pkg);
/* add package for removal to transaction */
void slapt_add_remove_to_transaction(slapt_transaction_t *, slapt_pkg_t *pkg);
/* add package to upgrade to transaction */
void slapt_add_upgrade_to_transaction(slapt_transaction_t *, slapt_pkg_t *installed_pkg, slapt_pkg_t *upgrade_pkg);
/* add package to reinstall to transaction */
void slapt_add_reinstall_to_transaction(slapt_transaction_t *, slapt_pkg_t *installed_pkg, slapt_pkg_t *upgrade_pkg);
/* add package to exclude to transaction */
void slapt_add_exclude_to_transaction(slapt_transaction_t *, slapt_pkg_t *pkg);
/* remove package from transaction, returns modified transaction */
slapt_transaction_t *slapt_remove_from_transaction(slapt_transaction_t *tran, slapt_pkg_t *pkg);

/* search transaction by package name.  returns true if found, false otherwise */
bool slapt_search_transaction(slapt_transaction_t *, char *pkg_name);
/* search transaction by package attributes, returns true if found, false otherwise */
bool slapt_search_transaction_by_pkg(slapt_transaction_t *tran, slapt_pkg_t *pkg);
/* searches the upgrade list of the transaction for the present of the package, returns true if found, false if not found */
bool slapt_search_upgrade_transaction(slapt_transaction_t *tran, slapt_pkg_t *pkg);

/* add dependencies for package to transaction, returns -1 on error, 0 otherwise */
int slapt_add_deps_to_trans(const slapt_config_t *global_config,
                            slapt_transaction_t *tran,
                            slapt_vector_t *avail_pkgs,
                            slapt_vector_t *installed_pkgs, slapt_pkg_t *pkg);

/* check to see if a package has a conflict already present in the transaction, returns conflicted package or NULL if none */
slapt_vector_t *slapt_is_conflicted(slapt_transaction_t *tran,
                                    slapt_vector_t *avail_pkgs,
                                    slapt_vector_t *installed_pkgs,
                                    slapt_pkg_t *pkg);

/* generate a list of suggestions based on the current packages in the transaction */
void slapt_generate_suggestions(slapt_transaction_t *tran);

/* free the transaction structure and it's members */
void slapt_free_transaction(slapt_transaction_t *);