]>
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
= "\n%%% $Id$\n";
25 #include "io_stream.h"
28 #include "filemanip.h"
31 /* io_stream needs a bit of tweaking to get rid of this. TODO */
33 /* this goes at the same time */
40 #include "package_version.h"
41 #include "cygpackage.h"
42 #include "package_meta.h"
43 #include "package_db.h"
45 static const char *standard_dirs
[] = {
65 hash::add_subdirs (String
const &tpath
)
68 char *path
= tpath
.cstr();
69 for (nonp
= path
; *nonp
== '\\' || *nonp
== '/'; nonp
++);
70 for (pp
= path
+ strlen (path
) - 1; pp
> nonp
; pp
--)
71 if (*pp
== '/' || *pp
== '\\')
76 for (i
= 0; standard_dirs
[i
]; i
++)
77 if (strcmp (standard_dirs
[i
] + 1, path
) == 0)
90 CategoryPackage::~CategoryPackage()
92 CategoryPackage
**temp
= &key
.packages
;
94 temp
= &((*temp
)->next
);
101 packagemeta::_actions
102 packagemeta::Default_action (0);
104 packagemeta::_actions
105 packagemeta::Install_action (1);
107 packagemeta::_actions
108 packagemeta::Reinstall_action (2);
110 packagemeta::_actions
111 packagemeta::Uninstall_action (3);
114 packagemeta::_actions::caption ()
127 // Pacify GCC: (all case options are checked above)
131 packagemeta::_actions
& packagemeta::_actions::operator++ ()
139 packagemeta::~packagemeta()
141 while (Categories
.number ())
143 CategoryPackage
*catpkg
= Categories
.removebyindex (1);
146 while (versions
.number ())
148 packageversion
*pv
= versions
.removebyindex(1);
154 packagemeta::add_version (packageversion
& thepkg
)
156 versions
.registerbyobject (thepkg
);
159 /* assumption: package thepkg is already in the metadata list. */
161 packagemeta::set_installed (packageversion
& thepkg
)
163 packageversion
*temp
= versions
.getbykey (thepkg
.key
);
168 /* uninstall a package if it's installed */
170 packagemeta::uninstall ()
174 /* this will need to be pushed down to the version, or even the source level
175 * to allow differences between formats to be seamlessly managed
176 * but for now: here is ok
179 String line
= installed
->getfirstfile ();
181 try_run_script ("/etc/preremove/", name
);
184 dirs
.add_subdirs (line
);
186 String d
= cygpath (String ("/") + line
);
187 DWORD dw
= GetFileAttributes (d
.cstr_oneuse());
188 if (dw
!= INVALID_FILE_ATTRIBUTES
189 && !(dw
& FILE_ATTRIBUTE_DIRECTORY
))
191 log (LOG_BABBLE
, String("unlink ")+ d
);
192 SetFileAttributes (d
.cstr_oneuse(), dw
& ~FILE_ATTRIBUTE_READONLY
);
193 DeleteFile (d
.cstr_oneuse());
195 /* Check for Windows shortcut of same name. */
197 dw
= GetFileAttributes (d
.cstr_oneuse());
198 if (dw
!= INVALID_FILE_ATTRIBUTES
199 && !(dw
& FILE_ATTRIBUTE_DIRECTORY
))
201 log (LOG_BABBLE
, String("unlink ") + d
);
202 SetFileAttributes (d
.cstr_oneuse(),
203 dw
& ~FILE_ATTRIBUTE_READONLY
);
204 DeleteFile (d
.cstr_oneuse());
206 line
= installed
->getnextfile ();
208 installed
->uninstall ();
210 dirs
.reverse_sort ();
212 while ((subdir
= dirs
.enumerate (subdir
)) != 0)
214 String d
= cygpath (String ("/") + subdir
);
215 if (RemoveDirectory (d
.cstr_oneuse()))
216 log (LOG_BABBLE
, String("rmdir ") + d
);
218 try_run_script ("/etc/postremove/", name
);
225 packagemeta::add_category (Category
& cat
)
227 /* add a new record for the package list */
228 CategoryPackage
& catpack
= Categories
.registerbykey (cat
);
233 packagemeta::SDesc () const
235 for (size_t n
= 1; n
<= versions
.number (); ++n
)
236 if (versions
[n
]->SDesc ().size())
237 return versions
[n
]->SDesc ();
241 /* Return an appropriate caption given the current action. */
243 packagemeta::action_caption ()
245 if (!desired
&& installed
)
249 else if (desired
== installed
&& desired
->binpicked
)
252 return db
.task
== PackageDB_Install
? "Reinstall" : "Retrieve";
254 else if (desired
== installed
&& desired
->srcpicked
)
255 /* FIXME: Redo source should come up if the tarball is already present locally */
257 else if (desired
== installed
) /* and neither src nor bin */
260 return desired
->Canonical_version ();
263 /* Set the next action given a current action. */
265 packagemeta::set_action (packageversion
* default_version
)
267 /* actions are the following:
269 for install modes (from net/local)
272 install the source for this version
273 and a boolean flag - force install to allow reinstallation, or bypassing requirements
275 install the source for the current version.
277 to uninstall a package, the desired version is set to NULL;
279 for mirroring modes (download only)
281 download this version
282 download source for this version
284 these are represented by the following:
285 the desired pointer in the packagemetadata indicated which version we are operating on.
286 if we are operating on the installed version, reinstall is a valid option.
287 for the selected version, forceinstall means Do an install no matter what, and
288 srcpicked means download the source.
290 The default action for any installed package is to install the 'curr version'
291 if it is not already installed.
293 The default action for any non-installed package is to do nothing.
295 To achieve a no-op, set desired==installed, and if (installed) set forceinstall=0 and
298 Iteration through versions should follow the following rules:
299 selected radio button (prev/curr/test) (show as reinstall if that is the
300 current version) ->source only (only if the package is installed) ->oldest version....s
301 kip version of radio button...
302 newest version->uninstall->no-op->selected radio button.
304 If any state cannot be set (ie because (say) no prev entry exists for a package
305 simply progress to the next option.
309 /* We were set to uninstall the package */
310 if (!desired
&& installed
)
312 /* No-op - keep whatever we've got */
316 desired
->binpicked
= 0;
317 desired
->srcpicked
= 0;
321 else if (desired
== installed
322 && (!installed
|| !(installed
->binpicked
|| installed
->srcpicked
)))
323 /* Install the default trust version - this is a 'reinstall' for installed
328 desired
= default_version
;
331 desired
->binpicked
= 1;
335 /* are we currently on the radio button selection and installed */
336 if (desired
== default_version
&& installed
&&
337 (!desired
|| desired
->binpicked
)
339 (desired
->src
.Cached () || desired
->src
.sites
.number ())))
341 /* source only this file */
343 desired
->binpicked
= 0;
344 desired
->srcpicked
= 1;
347 /* are we currently on source only or on the radio button but not installed */
348 else if ((desired
== installed
&& installed
349 && installed
->srcpicked
) || desired
== default_version
)
351 /* move onto the loop through versions */
352 desired
= versions
[1];
353 if (desired
== default_version
)
354 desired
= versions
.number () > 1 ? versions
[2] : NULL
;
357 desired
->binpicked
= 1;
358 desired
->srcpicked
= 0;
364 /* preserve the src tick box */
365 int source
= desired
->srcpicked
;
366 /* bump the version selected, skipping the radio button trust along the way */
368 for (n
= 1; n
<= versions
.number () && desired
!= versions
[n
]; n
++);
369 /* n points at pkg->desired */
371 if (n
<= versions
.number ())
373 if (default_version
== versions
[n
])
375 if (n
<= versions
.number ())
377 desired
= versions
[n
];
378 desired
->srcpicked
= source
;
382 /* went past the end - uninstall the package */
388 packagemeta::set_requirements (trusts deftrust
= TRUST_CURR
, size_t depth
= 0)
391 packagemeta
*required
;
393 if (!desired
|| (desired
!= installed
&& !desired
->binpicked
))
394 /* uninstall || source only */
397 dp
= desired
->required
;
399 /* cheap test for too much recursion */
404 if ((required
= db
.packages
.getbykey (dp
->package
)) == NULL
)
410 if (!required
->desired
)
412 /* it's set to uninstall */
413 required
->set_action (required
->trustp (deftrust
));
415 else if (required
->desired
!= required
->installed
416 && !required
->desired
->binpicked
)
418 /* it's set to change to a different version source only */
419 required
->desired
->binpicked
= 1;
421 /* does this requirement have requirements? */
422 changed
+= required
->set_requirements (deftrust
, depth
+ 1);
429 // Set a particular type of action.
431 packagemeta::set_action (_actions action
, packageversion
* default_version
)
434 if (action
== Default_action
)
436 // XXX fix the list use to allow const ref usage.
437 Category
tempCategory("Misc");
439 || Categories
.getbykey (db
.categories
.registerbykey ("Base"))
440 || Categories
.getbykey (tempCategory
))
442 desired
= default_version
;
445 desired
->binpicked
= desired
== installed
? 0 : 1;
446 desired
->srcpicked
= 0;
453 else if (action
== Install_action
)
455 desired
= default_version
;
458 if (desired
!= installed
)
459 desired
->binpicked
= 1;
461 desired
->binpicked
= 0;
462 desired
->srcpicked
= 0;
466 else if (action
== Reinstall_action
)
471 desired
->binpicked
= 1;
472 desired
->srcpicked
= 0;
475 else if (action
== Uninstall_action
)
This page took 0.05066 seconds and 5 git commands to generate.