]>
cygwin.com Git - cygwin-apps/setup.git/blob - package_meta.cc
2 * Copyright (c) 2001, Robert Collins.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <rbtcollins@hotmail.com>
17 static const char *cvsid
=
27 #include "io_stream.h"
30 #include "filemanip.h"
33 /* io_stream needs a bit of tweaking to get rid of this. TODO */
35 /* this goes at the same time */
42 #include "package_version.h"
43 #include "cygpackage.h"
44 #include "package_meta.h"
45 #include "package_db.h"
47 static const char *standard_dirs
[] = {
67 hash::add_subdirs (char const *tpath
)
70 char *path
= strdup (tpath
);
71 for (nonp
= path
; *nonp
== '\\' || *nonp
== '/'; nonp
++);
72 for (pp
= path
+ strlen (path
) - 1; pp
> nonp
; pp
--)
73 if (*pp
== '/' || *pp
== '\\')
78 for (i
= 0; standard_dirs
[i
]; i
++)
79 if (strcmp (standard_dirs
[i
] + 1, path
) == 0)
91 packagemeta::add_version (packageversion
& thepkg
)
93 versions
.registerbyobject (thepkg
);
96 /* assumption: package thepkg is already in the metadata list. */
98 packagemeta::set_installed (packageversion
& thepkg
)
100 packageversion
*temp
= versions
.getbykey (thepkg
.key
);
105 /* uninstall a package if it's installed */
107 packagemeta::uninstall ()
111 /* this will need to be pushed down to the version, or even the source level
112 * to allow differences between formats to be seamlessly managed
113 * but for now: here is ok
116 const char *line
= installed
->getfirstfile ();
118 try_run_script ("/etc/preremove/", name
);
121 dirs
.add_subdirs (line
);
123 char *d
= cygpath ("/", line
, NULL
);
124 DWORD dw
= GetFileAttributes (d
);
125 if (dw
!= 0xffffffff && !(dw
& FILE_ATTRIBUTE_DIRECTORY
))
127 log (LOG_BABBLE
, "unlink %s", d
);
130 line
= installed
->getnextfile ();
132 installed
->uninstall ();
134 dirs
.reverse_sort ();
136 while ((subdir
= dirs
.enumerate (subdir
)) != 0)
138 char *d
= cygpath ("/", subdir
, NULL
);
139 if (RemoveDirectory (d
))
140 log (LOG_BABBLE
, "rmdir %s", d
);
142 try_run_script ("/etc/postremove/", name
);
149 packagemeta::add_category (Category
& cat
)
151 /* add a new record for the package list */
152 CategoryPackage
& catpack
= Categories
.registerbykey (cat
);
157 packagemeta::SDesc () const
159 return versions
[1]->SDesc ();
162 /* Return an appropriate caption given the current action. */
164 packagemeta::action_caption ()
166 if (!desired
&& installed
)
170 else if (desired
== installed
&& desired
->binpicked
)
173 return db
.task
== PackageDB_Install
? "Reinstall" : "Retrieve";
175 else if (desired
== installed
&& desired
->srcpicked
)
176 /* FIXME: Redo source should come up if the tarball is already present locally */
178 else if (desired
== installed
) /* and neither src nor bin */
181 return desired
->Canonical_version ();
184 /* Set the next action given a current action. */
186 packagemeta::set_action (packageversion
* default_version
)
188 /* actions are the following:
190 for install modes (from net/local)
193 install the source for this version
194 and a boolean flag - force install to allow reinstallation, or bypassing requirements
196 install the source for the current version.
198 to uninstall a package, the desired version is set to NULL;
200 for mirroring modes (download only)
202 download this version
203 download source for this version
205 these are represented by the following:
206 the desired pointer in the packagemetadata indicated which version we are operating on.
207 if we are operating on the installed version, reinstall is a valid option.
208 for the selected version, forceinstall means Do an install no matter what, and
209 srcpicked means download the source.
211 The default action for any installed package is to install the 'curr version'
212 if it is not already installed.
214 The default action for any non-installed package is to do nothing.
216 To achieve a no-op, set desired==installed, and if (installed) set forceinstall=0 and
219 Iteration through versions should follow the following rules:
220 selected radio button (prev/curr/test) (show as reinstall if that is the
221 current version) ->source only (only if the package is installed) ->oldest version....s
222 kip version of radio button...
223 newest version->uninstall->no-op->selected radio button.
225 If any state cannot be set (ie because (say) no prev entry exists for a package
226 simply progress to the next option.
230 /* We were set to uninstall the package */
231 if (!desired
&& installed
)
233 /* No-op - keep whatever we've got */
237 desired
->binpicked
= 0;
238 desired
->srcpicked
= 0;
242 else if (desired
== installed
244 || !(installed
->binpicked
|| installed
->srcpicked
)))
245 /* Install the default trust version - this is a 'reinstall' for installed
250 desired
= default_version
;
253 desired
->binpicked
= 1;
257 /* are we currently on the radio button selection and installed */
258 if (desired
== default_version
&& installed
&&
259 (!desired
|| desired
->binpicked
)
261 (desired
->src
.Cached () || desired
->src
.sites
.number ())))
263 /* source only this file */
265 desired
->binpicked
= 0;
266 desired
->srcpicked
= 1;
269 /* are we currently on source only or on the radio button but not installed */
270 else if ((desired
== installed
&& installed
271 && installed
->srcpicked
) || desired
== default_version
)
273 /* move onto the loop through versions */
274 desired
= versions
[1];
275 if (desired
== default_version
)
276 desired
= versions
.number () > 1 ? versions
[2] : NULL
;
279 desired
->binpicked
= 1;
280 desired
->srcpicked
= 0;
286 /* preserve the src tick box */
287 int source
= desired
->srcpicked
;
288 /* bump the version selected, skipping the radio button trust along the way */
291 n
<= versions
.number ()
292 && desired
!= versions
[n
]; n
++);
293 /* n points at pkg->desired */
295 if (n
<= versions
.number ())
297 if (default_version
== versions
[n
])
299 if (n
<= versions
.number ())
301 desired
= versions
[n
];
302 desired
->srcpicked
= source
;
306 /* went past the end - uninstall the package */
This page took 0.048437 seconds and 5 git commands to generate.