]> cygwin.com Git - cygwin-apps/setup.git/blob - cygpackage.cc
* prereq.cc (PrereqChecker::getUnmetString): Improve dependency list
[cygwin-apps/setup.git] / cygpackage.cc
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 "cygpackage.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28
29 #include "io_stream.h"
30 #include "compress.h"
31
32 #include "package_version.h"
33 #include "cygpackage.h"
34 #include "LogSingleton.h"
35
36 /* this constructor creates an invalid package - further details MUST be provided */
37 cygpackage::cygpackage ():
38 name (),
39 vendor (),
40 packagev (),
41 canonical (),
42 fn (),
43 sdesc (),
44 ldesc (),
45 status (package_installed),
46 type (package_binary),
47 listdata (),
48 listfile ()
49 {
50 memset( getfilenamebuffer, '\0', MAX_PATH);
51
52 /* FIXME: query the install database for the currently installed
53 * version details
54 */
55 }
56
57 packageversion
58 cygpackage::createInstance (const std::string& pkgname,
59 const package_type_t type)
60 {
61 cygpackage *temp = new cygpackage;
62 temp->name = pkgname;
63 temp->type = type;
64 return packageversion(temp);
65 }
66
67 packageversion
68 cygpackage::createInstance (const std::string& pkgname,
69 const std::string& filename,
70 const std::string& version,
71 package_status_t const newstatus,
72 package_type_t const newtype)
73 {
74 cygpackage *temp = new cygpackage;
75 temp->name = pkgname;
76 temp->fn = filename;
77 temp->status = newstatus;
78 temp->type = newtype;
79 temp->setCanonicalVersion (version);
80 return packageversion(temp);
81 }
82
83 /* tell the version */
84 void
85 cygpackage::setCanonicalVersion (const std::string& version)
86 {
87 canonical = version;
88 char *start = strchr (canonical.c_str(), '-');
89 char*curr=start;
90 if (curr)
91 {
92 char *next;
93 while ((next = strchr (curr + 1, '-')))
94 curr = next;
95 /* curr = last - in the version string */
96 packagev = curr + 1;
97 char tvendor [version.size() +1];
98 strcpy (tvendor, version.c_str());
99 tvendor[curr - start] = '\0';
100 vendor=tvendor;
101 }
102 else
103 {
104 // FIXME: What's up with the "0"? It's probably a mistake, and should be
105 // "". It used to be written as 0, and was subject to a bizarre implicit
106 // conversion by the unwise String(int) constructor.
107 packagev = "0";
108 vendor = version;
109 }
110 }
111
112 cygpackage::~cygpackage ()
113 {
114 destroy ();
115 }
116
117 /* helper functions */
118
119 void
120 cygpackage::destroy ()
121 {
122 }
123
124 const std::string
125 cygpackage::getfirstfile ()
126 {
127 if (listdata)
128 delete listdata;
129 listfile =
130 io_stream::open ("cygfile:///etc/setup/" + name + ".lst.gz", "rb", 0);
131 listdata = compress::decompress (listfile);
132 if (!listdata)
133 return std::string();
134 /* std::string(NULL) will crash, so be careful to test for that. */
135 const char *result = listdata->gets (getfilenamebuffer, sizeof (getfilenamebuffer));
136 if (result == NULL)
137 log (LOG_PLAIN) << "Corrupt package listing for " << name << ", can't uninstall old files." << endLog;
138 return std::string (result ? result : "");
139 }
140
141 const std::string
142 cygpackage::getnextfile ()
143 {
144 if (listdata)
145 {
146 /* std::string(NULL) will crash, so be careful to test for that. */
147 const char *sz = listdata->gets (getfilenamebuffer,
148 sizeof (getfilenamebuffer));
149 if (sz)
150 return std::string(sz);
151 }
152 return std::string();
153 }
154
155 void
156 cygpackage::uninstall ()
157 {
158 if (listdata)
159 delete listdata;
160 listdata = 0;
161 io_stream::remove ("cygfile:///etc/setup/" + name + ".lst.gz");
162 }
163
164 const std::string
165 cygpackage::Name ()
166 {
167 return name;
168 }
169
170 const std::string
171 cygpackage::Vendor_version ()
172 {
173 return vendor;
174 }
175
176 const std::string
177 cygpackage::Package_version ()
178 {
179 return packagev;
180 }
181
182 std::string const
183 cygpackage::Canonical_version ()
184 {
185 return canonical;
186 }
187
188 void
189 cygpackage::set_sdesc (const std::string& desc)
190 {
191 sdesc = desc;
192 }
193
194 void
195 cygpackage::set_ldesc (const std::string& desc)
196 {
197 ldesc = desc;
198 }
199
200 #if 0
201 package_stability_t cygpackage::Stability ()
202 {
203 return stability;
204 }
205 #endif
This page took 0.043463 seconds and 5 git commands to generate.