]>
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
=
32 #include "io_stream.h"
35 #include "filemanip.h"
37 #include "package_version.h"
38 #include "cygpackage.h"
39 #include "package_db.h"
40 #include "package_meta.h"
45 packagedb::getpackagebyname (const char *search
)
47 /* dumb search, we can add a index and do a btree later */
49 while (index
< packagecount
)
51 if (!strcasecmp ((*packages
[index
]).name
, search
))
52 return packages
[index
];
58 packagedb::packagedb ()
64 /* no parameters. Read in the local installation database. */
65 db
= io_stream::open ("cygfile:///etc/setup/installed.db", "rt");
68 /* flush_local_db_package_data */
69 char line
[1000], pkgname
[1000], inst
[1000], src
[1000];
72 if (db
->gets (line
, 1000))
75 sscanf (line
, "%s %d", pkgname
, &instsz
);
76 if (!strcasecmp (pkgname
, "INSTALLED.DB") && instsz
== 2)
82 /* Later versions may not use installed.db other than to record the version. */
83 if (dbver
== 1 || dbver
== 2)
86 io_stream::open ("cygfile:///etc/setup/installed.db", "rt");
88 db
->gets (line
, 1000);
89 while (db
->gets (line
, 1000))
94 sscanf (line
, "%s %s %d %s %d", pkgname
, inst
, &instsz
, src
,
97 parseable
= parse_filename (inst
, f
);
101 packagemeta
*pkg
= getpackagebyname (pkgname
);
104 pkg
= new packagemeta (pkgname
, inst
);
105 /* we should install a new handler then not check this...
112 new cygpackage (pkgname
, inst
, instsz
, f
.ver
,
116 pkg
->add_version (*binary
);
117 pkg
->set_installed (*binary
);
118 pkg
->desired
= pkg
->installed
;
134 packagedb::getfirstpackage ()
143 packagedb::getnextpackage ()
146 if (packagecount
>= curr_package
)
147 return packages
[curr_package
];
152 packagedb::addpackage (packagemeta
& newpackage
)
154 if (getpackagebyname (newpackage
.name
))
157 if (packagecount
== packagespace
)
159 packagemeta
**newpackages
= (packagemeta
**) realloc (packages
,
169 packages
= newpackages
;
175 && strcasecmp (packages
[n
]->name
, newpackage
.name
) < 0; n
++);
177 memmove (&packages
[n
+ 1], &packages
[n
],
178 (packagecount
- n
) * sizeof (packagemeta
*));
179 packages
[n
] = &newpackage
;
187 /* naive approach - just dump the lot */
188 char const *odbn
= "cygfile:///etc/setup/installed.db";
189 char const *ndbn
= "cygfile:///etc/setup/installed.db.new";
191 io_stream::mkpath_p (PATH_TO_FILE
, ndbn
);
193 io_stream
*ndb
= io_stream::open (ndbn
, "wb");
196 return errno
? errno
: 1;
198 ndb
->write ("INSTALLED.DB 2\n", strlen ("INSTALLED.DB 2\n"));
199 if (getfirstpackage ())
201 packagemeta
*pkgm
= getfirstpackage ();
208 /* size here is irrelevant - as we can assume that this install source
209 * no longer exists, and it does not correlate to used disk space
210 * also note that we are writing a fictional install source
211 * to keep cygcheck happy.
213 sprintf (line
, "%s %s %d\n", pkgm
->name
,
214 concat (pkgm
->name
, "-",
215 pkgm
->installed
->Canonical_version (),
217 ndb
->write (line
, strlen (line
));
219 pkgm
= getnextpackage ();
225 io_stream::remove (odbn
);
227 if (io_stream::move (ndbn
, odbn
))
228 return errno
? errno
: 1;
232 packagemeta
& packagedb::registerpackage (char const *pkgname
)
236 getpackagebyname (pkgname
);
239 tmp
= new packagemeta (pkgname
);
246 packagedb::packages
=
248 size_t packagedb::packagecount
= 0;
249 size_t packagedb::packagespace
= 0;
251 packagedb::installeddbread
=
253 list
< Category
, char const *,
255 packagedb::categories
;
This page took 0.047237 seconds and 5 git commands to generate.