]>
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";
20 #include "package_meta.h"
26 #include "io_stream.h"
29 #include "filemanip.h"
31 #include "LogSingleton.h"
32 /* io_stream needs a bit of tweaking to get rid of this. TODO */
34 /* this goes at the same time */
41 #include "package_version.h"
42 #include "cygpackage.h"
43 #include "package_db.h"
49 static const char *standard_dirs
[] = {
69 hash::add_subdirs (String
const &tpath
)
72 char *path
= tpath
.cstr();
73 for (nonp
= path
; *nonp
== '\\' || *nonp
== '/'; nonp
++);
74 for (pp
= path
+ strlen (path
) - 1; pp
> nonp
; pp
--)
75 if (*pp
== '/' || *pp
== '\\')
80 for (i
= 0; standard_dirs
[i
]; i
++)
81 if (strcmp (standard_dirs
[i
] + 1, path
) == 0)
96 packagemeta::Default_action (0);
99 packagemeta::Install_action (1);
101 packagemeta::_actions
102 packagemeta::Reinstall_action (2);
104 packagemeta::_actions
105 packagemeta::Uninstall_action (3);
108 packagemeta::_actions::caption ()
121 // Pacify GCC: (all case options are checked above)
125 packagemeta::packagemeta (packagemeta
const &rhs
) :
126 name (rhs
.name
), key (rhs
.name
), installed_from (),
127 categories (rhs
.categories
), versions (rhs
.versions
),
128 installed (rhs
.installed
), prev (rhs
.prev
),
129 prevtimestamp (rhs
.prevtimestamp
), curr (rhs
.curr
),
130 currtimestamp (rhs
.currtimestamp
), exp (rhs
.exp
),
131 exptimestamp (rhs
.exptimestamp
), desired (rhs
.desired
),
132 architecture (rhs
.architecture
), priority (rhs
.priority
)
137 packagemeta::_actions
& packagemeta::_actions::operator++ ()
145 template<class T
> struct removeCategory
: public unary_function
<T
, void>
147 removeCategory(packagemeta
*pkg
) : _pkg (pkg
) {}
148 void operator() (T x
)
150 vector
<packagemeta
*> &aList
= packagedb::categories
[x
];
151 aList
.erase (find (aList
.begin(), aList
.end(), _pkg
));
157 packagemeta::~packagemeta()
159 for_each (categories
.begin (), categories
.end (), removeCategory
<String
> (this));
165 packagemeta::add_version (packageversion
& thepkg
)
167 /* todo: check return value */
168 versions
.insert (thepkg
);
171 /* assumption: package thepkg is already in the metadata list. */
173 packagemeta::set_installed (packageversion
& thepkg
)
175 set
<packageversion
>::const_iterator temp
= versions
.find (thepkg
);
176 if (temp
!= versions
.end())
180 /* uninstall a package if it's installed */
182 packagemeta::uninstall ()
186 /* this will need to be pushed down to the version, or even the source level
187 * to allow differences between formats to be seamlessly managed
188 * but for now: here is ok
191 String line
= installed
.getfirstfile ();
193 try_run_script ("/etc/preremove/", name
);
196 dirs
.add_subdirs (line
);
198 String d
= cygpath (String ("/") + line
);
199 DWORD dw
= GetFileAttributes (d
.cstr_oneuse());
200 if (dw
!= INVALID_FILE_ATTRIBUTES
201 && !(dw
& FILE_ATTRIBUTE_DIRECTORY
))
203 log (LOG_BABBLE
) << "unlink " << d
<< endLog
;
204 SetFileAttributes (d
.cstr_oneuse(), dw
& ~FILE_ATTRIBUTE_READONLY
);
205 DeleteFile (d
.cstr_oneuse());
207 /* Check for Windows shortcut of same name. */
209 dw
= GetFileAttributes (d
.cstr_oneuse());
210 if (dw
!= INVALID_FILE_ATTRIBUTES
211 && !(dw
& FILE_ATTRIBUTE_DIRECTORY
))
213 log (LOG_BABBLE
) << "unlink " << d
<< endLog
;
214 SetFileAttributes (d
.cstr_oneuse(),
215 dw
& ~FILE_ATTRIBUTE_READONLY
);
216 DeleteFile (d
.cstr_oneuse());
218 line
= installed
.getnextfile ();
220 installed
.uninstall ();
222 dirs
.reverse_sort ();
224 while ((subdir
= dirs
.enumerate (subdir
)) != 0)
226 String d
= cygpath (String ("/") + subdir
);
227 if (RemoveDirectory (d
.cstr_oneuse()))
228 log (LOG_BABBLE
) << "rmdir " << d
<< endLog
;
230 try_run_script ("/etc/postremove/", name
);
232 installed
= packageversion();
237 packagemeta::add_category (String
const &cat
)
239 if (categories
.find (cat
) != categories
.end())
241 /* add a new record for the package list */
242 packagedb::categories
[cat
].push_back (this);
243 categories
.insert (cat
);
247 hasSDesc(packageversion
const &pkg
)
249 return pkg
.SDesc().size();
253 packagemeta::SDesc () const
255 set
<packageversion
>::iterator i
= find_if (versions
.begin(), versions
.end(), hasSDesc
);
256 if (i
== versions
.end())
261 /* Return an appropriate caption given the current action. */
263 packagemeta::action_caption ()
265 if (!desired
&& installed
)
269 else if (desired
== installed
&& desired
.picked())
272 return db
.task
== PackageDB_Install
? "Reinstall" : "Retrieve";
274 else if (desired
== installed
&& desired
.sourcePackage() && desired
.sourcePackage().picked())
275 /* FIXME: Redo source should come up if the tarball is already present locally */
277 else if (desired
== installed
) /* and neither src nor bin */
280 return desired
.Canonical_version ();
283 /* Set the next action given a current action. */
285 packagemeta::set_action (packageversion
const &default_version
)
287 /* actions are the following:
289 for install modes (from net/local)
292 install the source for this version
293 and a boolean flag - force install to allow reinstallation, or bypassing requirements
295 install the source for the current version.
297 to uninstall a package, the desired version is set to NULL;
299 for mirroring modes (download only)
301 download this version
302 download source for this version
304 these are represented by the following:
305 the desired pointer in the packagemetadata indicated which version we are operating on.
306 if we are operating on the installed version, reinstall is a valid option.
307 for the selected version, forceinstall means Do an install no matter what, and
308 srcpicked means download the source.
310 The default action for any installed package is to install the 'curr version'
311 if it is not already installed.
313 The default action for any non-installed package is to do nothing.
315 To achieve a no-op, set desired==installed, and if (installed) set forceinstall=0 and
318 Iteration through versions should follow the following rules:
319 selected radio button (prev/curr/test) (show as reinstall if that is the
320 current version) ->source only (only if the package is installed) ->oldest version....s
321 kip version of radio button...
322 newest version->uninstall->no-op->selected radio button.
324 If any state cannot be set (ie because (say) no prev entry exists for a package
325 simply progress to the next option.
329 /* We were set to uninstall the package */
330 if (!desired
&& installed
)
332 /* No-op - keep whatever we've got */
336 desired
.pick (false);
337 desired
.sourcePackage().pick (false);
341 else if (desired
== installed
&&
343 // neither bin nor source are being installed
344 (!(installed
.picked() || installed
.sourcePackage().picked()) &&
345 // bin or source are available
346 (installed
.accessible() || installed
.sourcePackage().accessible()) ))
348 /* Install the default trust version - this is a 'reinstall' for installed
352 desired
= default_version
;
355 if (desired
.accessible())
358 desired
.sourcePackage().pick (true);
362 /* are we currently on the radio button selection and installed */
363 if (desired
== default_version
&& installed
&&
364 (!desired
|| desired
.picked())
365 && (desired
&& desired
.sourcePackage().accessible())
368 /* source only this file */
370 desired
.pick (false);
371 desired
.sourcePackage().pick (true);
374 /* are we currently on source only or on the radio button but not installed */
375 else if ((desired
== installed
376 && installed
.sourcePackage().picked ()) || desired
== default_version
)
378 /* move onto the loop through versions */
379 set
<packageversion
>::iterator i
= versions
.begin();
380 if (*i
== default_version
)
382 if (i
!= versions
.end())
385 desired
.pick (desired
.accessible());
386 desired
.sourcePackage ().pick (false);
389 desired
= packageversion ();
394 /* preserve the src tick box */
395 bool sourceticked
= desired
.sourcePackage().picked();
396 /* bump the version selected, skipping the radio button trust along the way */
397 set
<packageversion
>::iterator i
;
398 for (i
=versions
.begin(); i
!= versions
.end() && *i
!= desired
; ++i
);
399 /* i points at desired in the versions set */
401 if (i
!= versions
.end ())
403 if (default_version
== *i
)
405 if (i
!= versions
.end ())
408 if (desired
.sourcePackage().accessible ())
409 desired
.sourcePackage ().pick (sourceticked
);
411 desired
.sourcePackage ().pick (false);
415 /* went past the end - uninstall the package */
416 desired
= packageversion ();
421 packagemeta::set_requirements (trusts deftrust
, size_t depth
)
424 /* handle build-depends */
425 if (depth
== 0 && desired
.sourcePackage ().picked())
426 changed
+= desired
.sourcePackage ().set_requirements (deftrust
, depth
+ 1);
427 if (!desired
|| (desired
!= installed
&& !desired
.picked ()))
428 /* uninstall || source only */
431 return changed
+ desired
.set_requirements (deftrust
, depth
);
435 // Set a particular type of action.
437 packagemeta::set_action (_actions action
, packageversion
const &default_version
)
439 if (action
== Default_action
)
442 || categories
.find ("Base") != categories
.end ()
443 || categories
.find ("Misc") != categories
.end ())
445 desired
= default_version
;
448 desired
.pick (desired
== installed
);
449 desired
.sourcePackage ().pick (false);
453 desired
= packageversion ();
456 else if (action
== Install_action
)
458 desired
= default_version
;
461 if (desired
!= installed
)
462 if (desired
.accessible ())
465 desired
.sourcePackage ().pick (false);
469 desired
.pick (false);
470 desired
.sourcePackage ().pick (true);
474 desired
.pick (false);
475 desired
.sourcePackage ().pick (false);
480 else if (action
== Reinstall_action
)
486 desired
.sourcePackage ().pick (false);
489 else if (action
== Uninstall_action
)
491 desired
= packageversion ();
496 packagemeta::accessible () const
498 for (set
<packageversion
>::iterator i
=versions
.begin();
499 i
!= versions
.end(); ++i
)
506 packagemeta::sourceAccessible () const
508 for (set
<packageversion
>::iterator i
=versions
.begin();
509 i
!= versions
.end(); ++i
)
511 packageversion bin
=*i
;
512 if (bin
.sourcePackage().accessible())
This page took 0.060103 seconds and 5 git commands to generate.