]>
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
=
31 #include "io_stream.h"
34 #include "filemanip.h"
36 #include "package_version.h"
37 #include "cygpackage.h"
38 #include "package_db.h"
39 #include "package_meta.h"
43 packagedb::packagedb ()
48 /* no parameters. Read in the local installation database. */
49 db
= io_stream::open ("cygfile:///etc/setup/installed.db", "rt");
52 /* flush_local_db_package_data */
53 char line
[1000], pkgname
[1000], inst
[1000], src
[1000];
56 if (db
->gets (line
, 1000))
59 sscanf (line
, "%s %d", pkgname
, &instsz
);
60 if (!strcasecmp (pkgname
, "INSTALLED.DB") && instsz
== 2)
66 /* Later versions may not use installed.db other than to record the version. */
67 if (dbver
== 1 || dbver
== 2)
70 io_stream::open ("cygfile:///etc/setup/installed.db", "rt");
72 db
->gets (line
, 1000);
73 while (db
->gets (line
, 1000))
78 sscanf (line
, "%s %s %d %s %d", pkgname
, inst
, &instsz
, src
,
81 parseable
= parse_filename (inst
, f
);
85 packagemeta
*pkg
= packages
.getbykey (pkgname
);
88 pkg
= new packagemeta (pkgname
, inst
);
89 /* we should install a new handler then not check this...
96 new cygpackage (pkgname
, inst
, instsz
, f
.ver
,
100 pkg
->add_version (*binary
);
101 pkg
->set_installed (*binary
);
102 pkg
->desired
= pkg
->installed
;
103 packages
.registerbyobject (*pkg
);
120 /* naive approach - just dump the lot */
121 char const *odbn
= "cygfile:///etc/setup/installed.db";
122 char const *ndbn
= "cygfile:///etc/setup/installed.db.new";
124 io_stream::mkpath_p (PATH_TO_FILE
, ndbn
);
126 io_stream
*ndb
= io_stream::open (ndbn
, "wb");
128 // XXX if this failed, try removing any existing .new database?
130 return errno
? errno
: 1;
132 ndb
->write ("INSTALLED.DB 2\n", strlen ("INSTALLED.DB 2\n"));
133 for (size_t n
= 1; n
<= packages
.number (); n
++)
135 packagemeta
& pkgm
= *packages
[n
];
140 /* size here is irrelevant - as we can assume that this install source
141 * no longer exists, and it does not correlate to used disk space
142 * also note that we are writing a fictional install source
143 * to keep cygcheck happy.
145 sprintf (line
, "%s %s %d\n", pkgm
.name
.cstr_oneuse(),
146 concat (pkgm
.name
.cstr_oneuse(), "-",
147 pkgm
.installed
->Canonical_version ().cstr_oneuse(),
149 ndb
->write (line
, strlen (line
));
155 io_stream::remove (odbn
);
157 if (io_stream::move (ndbn
, odbn
))
158 return errno
? errno
: 1;
163 packagedb::installeddbread
=
165 list
< packagemeta
, String
,
166 String::casecompare
>
168 list
< Category
, String
,
169 String::casecompare
>
170 packagedb::categories
;
This page took 0.044227 seconds and 5 git commands to generate.