]>
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
=
30 #include "io_stream.h"
33 #include "filemanip.h"
35 #include "package_version.h"
36 #include "cygpackage.h"
37 #include "package_db.h"
38 #include "package_meta.h"
42 packagedb::packagedb ()
47 /* no parameters. Read in the local installation database. */
48 db
= io_stream::open ("cygfile:///etc/setup/installed.db", "rt");
51 /* flush_local_db_package_data */
52 char line
[1000], pkgname
[1000], inst
[1000], src
[1000];
55 if (db
->gets (line
, 1000))
58 sscanf (line
, "%s %d", pkgname
, &instsz
);
59 if (!strcasecmp (pkgname
, "INSTALLED.DB") && instsz
== 2)
65 /* Later versions may not use installed.db other than to record the version. */
66 if (dbver
== 1 || dbver
== 2)
69 io_stream::open ("cygfile:///etc/setup/installed.db", "rt");
71 db
->gets (line
, 1000);
72 while (db
->gets (line
, 1000))
77 sscanf (line
, "%s %s %d %s %d", pkgname
, inst
, &instsz
, src
,
80 parseable
= parse_filename (inst
, f
);
84 packagemeta
*pkg
= packages
.getbykey (pkgname
);
87 pkg
= new packagemeta (pkgname
, inst
);
88 /* we should install a new handler then not check this...
95 new cygpackage (pkgname
, inst
, instsz
, f
.ver
,
99 pkg
->add_version (*binary
);
100 pkg
->set_installed (*binary
);
101 pkg
->desired
= pkg
->installed
;
102 packages
.registerbyobject (*pkg
);
119 /* naive approach - just dump the lot */
120 char const *odbn
= "cygfile:///etc/setup/installed.db";
121 char const *ndbn
= "cygfile:///etc/setup/installed.db.new";
123 io_stream::mkpath_p (PATH_TO_FILE
, ndbn
);
125 io_stream
*ndb
= io_stream::open (ndbn
, "wb");
127 // XXX if this failed, try removing any existing .new database?
129 return errno
? errno
: 1;
131 ndb
->write ("INSTALLED.DB 2\n", strlen ("INSTALLED.DB 2\n"));
132 for (size_t n
= 1; n
<= packages
.number (); n
++)
134 packagemeta
& pkgm
= *packages
[n
];
139 /* size here is irrelevant - as we can assume that this install source
140 * no longer exists, and it does not correlate to used disk space
141 * also note that we are writing a fictional install source
142 * to keep cygcheck happy.
144 sprintf (line
, "%s %s %d\n", pkgm
.name
.cstr_oneuse(),
145 (pkgm
.name
+ "-" + pkgm
.installed
->Canonical_version () +
146 ".tar.bz2").cstr_oneuse(), 0);
147 ndb
->write (line
, strlen (line
));
153 io_stream::remove (odbn
);
155 if (io_stream::move (ndbn
, odbn
))
156 return errno
? errno
: 1;
161 packagedb::installeddbread
=
163 list
< packagemeta
, String
,
164 String::casecompare
>
166 list
< Category
, String
,
167 String::casecompare
>
168 packagedb::categories
;
This page took 0.040757 seconds and 5 git commands to generate.