]>
Commit | Line | Data |
---|---|---|
7939f6d1 RC |
1 | /* |
2 | * Copyright (c) 2001, Robert Collins. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Robert Collins <rbtcollins@hotmail.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | /* this is the parent class for all package operations. | |
17 | */ | |
18 | ||
19 | #if 0 | |
20 | static const char *cvsid = | |
21 | "\n%%% $Id$\n"; | |
22 | #endif | |
23 | ||
24 | #include <stdio.h> | |
25 | #include <stdlib.h> | |
26 | #include <unistd.h> | |
3c054baf | 27 | #include "String++.h" |
7b606ae5 | 28 | |
7939f6d1 RC |
29 | #include "io_stream.h" |
30 | #include "compress.h" | |
7b606ae5 | 31 | |
fa0c0d10 | 32 | #include "package_version.h" |
7939f6d1 RC |
33 | #include "cygpackage.h" |
34 | ||
bb849dbd | 35 | /* this constructor creates an invalid package - further details MUST be provided */ |
3c054baf RC |
36 | cygpackage::cygpackage (String const &pkgname): |
37 | name (pkgname), | |
076654e7 RC |
38 | vendor (), |
39 | packagev (), | |
40 | canonical (), | |
41 | fn (), | |
42 | sdesc (), | |
43 | ldesc (), | |
7b606ae5 RC |
44 | status (package_installed), |
45 | type (package_binary), | |
076654e7 RC |
46 | listdata (), |
47 | listfile () | |
7939f6d1 | 48 | { |
bb849dbd RC |
49 | memset( getfilenamebuffer, '\0', _MAX_PATH); |
50 | ||
7939f6d1 RC |
51 | /* FIXME: query the install database for the currently installed |
52 | * version details | |
53 | */ | |
54 | } | |
55 | ||
56 | /* create a package given explicit details - perhaps should be modified to take the | |
57 | filename and do it's own parsing? */ | |
3c054baf RC |
58 | cygpackage::cygpackage (String const &pkgname, String const &filename, size_t const fs, |
59 | String const &version, package_status_t const newstatus, | |
60 | package_type_t const newtype): | |
61 | name (pkgname), | |
62 | fn (filename), | |
076654e7 RC |
63 | sdesc (), |
64 | ldesc (), | |
7b606ae5 RC |
65 | status (newstatus), |
66 | type (newtype), | |
076654e7 RC |
67 | listdata (), |
68 | listfile (), | |
7b606ae5 | 69 | filesize (fs) |
7939f6d1 | 70 | { |
bb849dbd RC |
71 | memset( getfilenamebuffer, '\0', _MAX_PATH); |
72 | set_canonical_version (version); | |
73 | } | |
7939f6d1 | 74 | |
bb849dbd RC |
75 | /* tell the version */ |
76 | void | |
3c054baf | 77 | cygpackage::set_canonical_version (String const &version) |
bb849dbd | 78 | { |
3c054baf RC |
79 | canonical = version; |
80 | char *start = strchr (canonical.cstr_oneuse(), '-'); | |
81 | char*curr=start; | |
7939f6d1 | 82 | if (curr) |
7b606ae5 RC |
83 | { |
84 | char *next; | |
85 | while ((next = strchr (curr + 1, '-'))) | |
86 | curr = next; | |
87 | /* curr = last - in the version string */ | |
3c054baf RC |
88 | packagev = curr + 1; |
89 | char tvendor [version.size() +1]; | |
90 | strcpy (tvendor, version.cstr_oneuse()); | |
91 | tvendor[curr - start] = '\0'; | |
92 | vendor=tvendor; | |
7b606ae5 | 93 | } |
7939f6d1 | 94 | else |
7b606ae5 RC |
95 | { |
96 | packagev = 0; | |
3c054baf | 97 | vendor = version; |
7b606ae5 | 98 | } |
bb849dbd | 99 | key = canonical; |
7939f6d1 RC |
100 | } |
101 | ||
102 | cygpackage::~cygpackage () | |
103 | { | |
bb849dbd | 104 | destroy (); |
7939f6d1 RC |
105 | } |
106 | ||
107 | /* helper functions */ | |
108 | ||
109 | void | |
110 | cygpackage::destroy () | |
111 | { | |
7939f6d1 RC |
112 | } |
113 | ||
3c054baf | 114 | String const |
7939f6d1 RC |
115 | cygpackage::getfirstfile () |
116 | { | |
117 | if (listdata) | |
118 | delete listdata; | |
7b606ae5 | 119 | listfile = |
3c054baf | 120 | io_stream::open (String ("cygfile:///etc/setup/") + name + ".lst.gz", "rb"); |
7939f6d1 | 121 | listdata = compress::decompress (listfile); |
7939f6d1 RC |
122 | if (!listdata) |
123 | return 0; | |
bb849dbd | 124 | return listdata->gets (getfilenamebuffer, sizeof (getfilenamebuffer)); |
7939f6d1 RC |
125 | } |
126 | ||
3c054baf | 127 | String const |
7939f6d1 RC |
128 | cygpackage::getnextfile () |
129 | { | |
130 | if (listdata) | |
bb849dbd | 131 | return listdata->gets (getfilenamebuffer, sizeof (getfilenamebuffer)); |
7939f6d1 RC |
132 | return 0; |
133 | } | |
134 | ||
fa0c0d10 RC |
135 | void |
136 | cygpackage::uninstall () | |
137 | { | |
138 | if (listdata) | |
139 | delete listdata; | |
140 | listdata = 0; | |
3c054baf | 141 | io_stream::remove (String("cygfile:///etc/setup/") + name + ".lst.gz"); |
fa0c0d10 | 142 | } |
7939f6d1 | 143 | |
3c054baf | 144 | String const |
7939f6d1 RC |
145 | cygpackage::Name () |
146 | { | |
147 | return name; | |
148 | } | |
149 | ||
3c054baf | 150 | String const |
7939f6d1 RC |
151 | cygpackage::Vendor_version () |
152 | { | |
153 | return vendor; | |
154 | } | |
155 | ||
3c054baf | 156 | String const |
7939f6d1 RC |
157 | cygpackage::Package_version () |
158 | { | |
159 | return packagev; | |
160 | } | |
161 | ||
3c054baf | 162 | String const |
bb849dbd RC |
163 | cygpackage::Canonical_version () |
164 | { | |
165 | return canonical; | |
166 | } | |
167 | ||
168 | void | |
3c054baf | 169 | cygpackage::set_sdesc (String const &desc) |
bb849dbd | 170 | { |
3c054baf | 171 | sdesc = desc; |
bb849dbd RC |
172 | } |
173 | ||
174 | void | |
3c054baf | 175 | cygpackage::set_ldesc (String const &desc) |
bb849dbd | 176 | { |
3c054baf | 177 | ldesc = desc; |
bb849dbd RC |
178 | } |
179 | ||
7939f6d1 | 180 | #if 0 |
bb849dbd | 181 | package_stability_t cygpackage::Stability () |
7939f6d1 RC |
182 | { |
183 | return stability; | |
184 | } | |
185 | #endif |