Modify eu-strip option to perform strip in post script of rpm package & add option...
[platform/upstream/rpm.git] / lib / rpmfs.c
1 #include "system.h"
2 #include "lib/rpmfs.h"
3 #include "debug.h"
4
5 struct rpmfs_s {
6     unsigned int fc;
7
8     rpm_fstate_t * states;
9     rpmFileAction * actions;    /*!< File disposition(s). */
10
11     sharedFileInfo replaced;    /*!< (TR_ADDED) to be replaced files in the rpmdb */
12     int numReplaced;
13     int allocatedReplaced;
14 };
15
16 rpmfs rpmfsNew(rpm_count_t fc, int initState)
17 {
18     rpmfs fs = xcalloc(1, sizeof(*fs));
19     fs->fc = fc;
20     fs->actions = xmalloc(fs->fc * sizeof(*fs->actions));
21     memset(fs->actions, FA_UNKNOWN, fs->fc * sizeof(*fs->actions));
22     if (initState) {
23         fs->states = xmalloc(sizeof(*fs->states) * fs->fc);
24         memset(fs->states, RPMFILE_STATE_NORMAL, fs->fc);
25     }
26     return fs;
27 }
28
29 rpmfs rpmfsFree(rpmfs fs)
30 {
31     if (fs != NULL) {
32         free(fs->replaced);
33         free(fs->states);
34         free(fs->actions);
35         memset(fs, 0, sizeof(*fs)); /* trash and burn */
36         free(fs);
37     }
38     return NULL;
39 }
40
41 rpm_count_t rpmfsFC(rpmfs fs)
42 {
43     return (fs != NULL) ? fs->fc : 0;
44 }
45
46 void rpmfsAddReplaced(rpmfs fs, int pkgFileNum, char rstate,
47                         int otherPkg, int otherFileNum)
48 {
49     if (!fs->replaced) {
50         fs->replaced = xcalloc(3, sizeof(*fs->replaced));
51         fs->allocatedReplaced = 3;
52     }
53     if (fs->numReplaced>=fs->allocatedReplaced) {
54         fs->allocatedReplaced += (fs->allocatedReplaced>>1) + 2;
55         fs->replaced = xrealloc(fs->replaced, fs->allocatedReplaced*sizeof(*fs->replaced));
56     }
57     fs->replaced[fs->numReplaced].pkgFileNum = pkgFileNum;
58     fs->replaced[fs->numReplaced].rstate = rstate;
59     fs->replaced[fs->numReplaced].otherPkg = otherPkg;
60     fs->replaced[fs->numReplaced].otherFileNum = otherFileNum;
61
62     fs->numReplaced++;
63 }
64
65 sharedFileInfo rpmfsGetReplaced(rpmfs fs)
66 {
67     if (fs && fs->numReplaced)
68         return fs->replaced;
69     else
70         return NULL;
71 }
72
73 sharedFileInfo rpmfsNextReplaced(rpmfs fs , sharedFileInfo replaced)
74 {
75     if (fs && replaced) {
76         replaced++;
77         if (replaced - fs->replaced < fs->numReplaced)
78             return replaced;
79     }
80     return NULL;
81 }
82
83 void rpmfsSetState(rpmfs fs, unsigned int ix, rpmfileState state)
84 {
85     assert(ix < fs->fc);
86     fs->states[ix] = state;
87 }
88
89 rpmfileState rpmfsGetState(rpmfs fs, unsigned int ix)
90 {
91     assert(ix < fs->fc);
92     if (fs->states) return fs->states[ix];
93     return RPMFILE_STATE_MISSING;
94 }
95
96 rpm_fstate_t * rpmfsGetStates(rpmfs fs)
97 {
98     return fs->states;
99 }
100
101 rpmFileAction rpmfsGetAction(rpmfs fs, unsigned int ix)
102 {
103     rpmFileAction action;
104     if (fs->actions != NULL && ix < fs->fc) {
105         action = fs->actions[ix];
106     } else {
107         action = FA_UNKNOWN;
108     }
109     return action;
110 }
111
112 void rpmfsSetAction(rpmfs fs, unsigned int ix, rpmFileAction action)
113 {
114     if (fs->actions != NULL && ix < fs->fc) {
115         fs->actions[ix] = action;
116     }
117 }