]> cygwin.com Git - cygwin-apps/setup.git/blob - ScanFindVisitor.cc
2002-05-19 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / ScanFindVisitor.cc
1 /*
2 * Copyright (c) 2002 Robert Collins.
3 *
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.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Robert Collins <robertc@hotmail.com>
13 *
14 */
15
16 #if 0
17 static const char *cvsid =
18 "\n%%% $Id$\n";
19 #endif
20
21 #include "ScanFindVisitor.h"
22 #include "filemanip.h"
23 #include "IniDBBuilder.h"
24
25 ScanFindVisitor::ScanFindVisitor(IniDBBuilder &aBuilder) : _Builder (aBuilder) {}
26 ScanFindVisitor::~ScanFindVisitor(){}
27
28 /* look for potential packages we can add to the in-memory package
29 * database
30 */
31 void
32 ScanFindVisitor::visitFile(String const &basePath, const WIN32_FIND_DATA *theFile)
33 {
34 // Sanity check: Does the file look like a package ?
35 fileparse f;
36 if (!parse_filename (theFile->cFileName, f))
37 return;
38
39 // Sanity check: Zero length package files get thrown out.
40 if (!(theFile->nFileSizeLow || theFile->nFileSizeHigh))
41 return;
42
43 // Build a new package called f.pkg
44 _Builder.buildPackage (f.pkg);
45
46 // Set the version we are bulding
47 _Builder.buildPackageVersion (f.ver);
48
49 // Add the file as a installable package
50 if (!f.what.size())
51 //assume binary
52 _Builder.buildPackageInstall (basePath + theFile->cFileName, theFile->nFileSizeLow);
53 else
54 // patch or src, assume src until someone complains
55 _Builder.buildPackageSource (basePath + theFile->cFileName, theFile->nFileSizeLow);
56
57 // TODO: Review the below code. We may wish to reinstate it *somewhere*.
58
59 #if 0
60 /* Scan existing package list looking for a match between a known
61 package and a tar archive on disk.
62 While scanning, keep track of appropriate "holes" in the trust
63 table where a tar file could be put if no known entry
64 exists.
65
66 We have 4 specific insertion points and one generic point.
67 The generic point is in versioned order in the package version array.
68 The specific points are
69 *installed
70 *prev
71 *curr
72 *exp.
73
74 if the version number matches a version in the db,
75 we simply add this as a mirror source to that version.
76 If it matches no version, we add a new version to the db.
77
78 Lastly if the version number does not matche one of installed/prev/current/exp
79 AND we had to create a new version entry
80 we apply the following heuristic:
81 if there is no exp, we link this in exp.
82 If there is an exp and this is higher, we link this in exp, and
83 if there is no curr, bump what was in exp to curr. If there was a curr, we leave it be.
84 if this is lower than exp, and there is no curr, link as curr. If there is a curr, leave it be.
85 If this is lower than curr, and there is no prev, link as prev, if there is a prev, leave it be.
86
87 Whilst this logic is potentially wrong from time to time, it guarantees that
88 setup.ini defined stability won't be altered unintentially. An alternative is to
89 mark setup.ini defined prev/curr/exp packages as such, when this algorithm, can
90 get smarter.
91
92 So, if setup.ini knows that ash-20010425-1.tar.gz is the current
93 version and there is an ash-20010426-1.tar.gz in the current directory,
94 the 20010426 version will be placed in the "test" slot, assuming that
95 there is no test version listed in setup.ini. */
96
97 int added = 0;
98 for (size_t n = 1; n <= pkg->versions.number (); n++)
99 {
100 if (!f.ver.casecompare (pkg->versions[n]->Canonical_version ()))
101 {
102 if (f.what == String ())
103 {
104 //bin package
105 pkg->versions[n]->bin.set_cached (String ("file://") + basePath + theFile->cFileName);
106 }
107 else if (f.what == "src")
108 {
109 //src package
110 pkg->versions[n]->src.set_cached (String ("file://") + basePath + theFile->cFileName);
111 }
112 added = 1;
113 }
114 }
115 if (!added)
116 {
117 #if 0
118 // Do we want old versions to show up
119 packageversion *pv = new cygpackage (f.pkg);
120 ((cygpackage *) pv)->set_canonical_version (f.ver);
121 if (!f.what.size ())
122 pv->bin.set_cached (String ("file://") + path);
123 else
124 // patch or src, assume src until someone complains
125 pv->src.set_cached (String ("file://") + path);
126 pkg->add_version (*pv);
127
128 #endif
129
130 /* And now the hole finder */
131 #if 0
132 if (!pkg->exp)
133 pkg->exp = thenewver;
134 else if (strcasecmp (f.ver, pkg->versions[n]->Canonicalversion ()) < 0)
135 /* try curr */
136 if (!pkg->curr)
137 pkg->curr = thenewver;
138 else if (strcasecmp (f.ver, pkg->versions[n]->Canonicalversion ()) <
139 0)
140 /* try prev */
141 if (!pkg->prev)
142 pkg->prev = thenewver;
143 #endif
144 }
145 #endif
146 }
This page took 0.042709 seconds and 5 git commands to generate.