]>
cygwin.com Git - cygwin-apps/setup.git/blob - package_db.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>
16 /* this is the package database class.
17 * It lists all known packages, including custom ones, ones from a mirror and
22 static const char *cvsid
=
33 #include "io_stream.h"
36 #include "filemanip.h"
38 #include "package_version.h"
39 #include "cygpackage.h"
40 #include "package_db.h"
41 #include "package_meta.h"
45 packagedb::packagedb ()
50 /* no parameters. Read in the local installation database. */
51 db
= io_stream::open ("cygfile:///etc/setup/installed.db", "rt");
54 /* flush_local_db_package_data */
55 char line
[1000], pkgname
[1000], inst
[1000], src
[1000];
58 if (db
->gets (line
, 1000))
61 sscanf (line
, "%s %d", pkgname
, &instsz
);
62 if (!strcasecmp (pkgname
, "INSTALLED.DB") && instsz
== 2)
68 /* Later versions may not use installed.db other than to record the version. */
69 if (dbver
== 1 || dbver
== 2)
72 io_stream::open ("cygfile:///etc/setup/installed.db", "rt");
74 db
->gets (line
, 1000);
75 while (db
->gets (line
, 1000))
84 sscanf (line
, "%s %s %d %s %d", pkgname
, inst
, &instsz
, src
,
87 if (pkgname
[0] == '\0' || inst
[0] == '\0')
91 parseable
= parse_filename (inst
, f
);
95 packagemeta
*pkg
= packages
.getbykey (pkgname
);
98 pkg
= new packagemeta (pkgname
, inst
);
99 /* we should install a new handler then not check this...
105 packageversion binary
=
106 cygpackage::createInstance (pkgname
, inst
, instsz
, f
.ver
,
110 pkg
->add_version (binary
);
111 pkg
->set_installed (binary
);
112 pkg
->desired
= pkg
->installed
;
113 packages
.registerbyobject (*pkg
);
130 /* naive approach - just dump the lot */
131 char const *odbn
= "cygfile:///etc/setup/installed.db";
132 char const *ndbn
= "cygfile:///etc/setup/installed.db.new";
134 io_stream::mkpath_p (PATH_TO_FILE
, ndbn
);
136 io_stream
*ndb
= io_stream::open (ndbn
, "wb");
138 // XXX if this failed, try removing any existing .new database?
140 return errno
? errno
: 1;
142 ndb
->write ("INSTALLED.DB 2\n", strlen ("INSTALLED.DB 2\n"));
143 for (size_t n
= 1; n
<= packages
.number (); n
++)
145 packagemeta
& pkgm
= *packages
[n
];
148 /* size here is irrelevant - as we can assume that this install source
149 * no longer exists, and it does not correlate to used disk space
150 * also note that we are writing a fictional install source
151 * to keep cygcheck happy.
154 line
= pkgm
.name
+ " " + pkgm
.name
+ "-" +
155 pkgm
.installed
.Canonical_version () + ".tar.bz2 0\n";
156 ndb
->write (line
.cstr_oneuse(), line
.size());
162 io_stream::remove (odbn
);
164 if (io_stream::move (ndbn
, odbn
))
165 return errno
? errno
: 1;
170 packagedb::findBinary (PackageSpecification
const &spec
) const
172 for (size_t n
= 1; n
<= packages
.number (); ++n
)
174 packagemeta
& pkgm
= *packages
[n
];
175 for (set
<packageversion
>::iterator i
=pkgm
.versions
.begin();
176 i
!= pkgm
.versions
.end(); ++i
)
177 if (spec
.satisfies (*i
))
184 packagedb::findSource (PackageSpecification
const &spec
) const
186 for (vector
<packagemeta
*>::iterator n
=sourcePackages
.begin();
187 n
!= sourcePackages
.end(); ++n
)
189 for (set
<packageversion
>::iterator i
= (*n
)->versions
.begin();
190 i
!= (*n
)->versions
.end(); ++i
)
191 if (spec
.satisfies (*i
))
198 packagedb::installeddbread
=
200 list
< packagemeta
, String
,
201 String::casecompare
>
203 list
< Category
, String
,
204 String::casecompare
>
205 packagedb::categories
;
206 vector
<packagemeta
*> packagedb::sourcePackages
;
This page took 0.041944 seconds and 5 git commands to generate.