3 # Sanity check the database
4 # Copyright (C) 2000, 2001 James Troup <james@nocrew.org>
5 # $Id: tea,v 1.15 2002-01-19 18:57:49 troup Exp $
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # And, lo, a great and menacing voice rose from the depths, and with
22 # great wrath and vehemence it's voice boomed across the
23 # land... ``hehehehehehe... that *tickles*''
26 ################################################################################
28 import pg, sys, os, string, stat, time
29 import utils, db_access
30 import apt_pkg, apt_inst;
32 ################################################################################
41 current_time = time.time();
43 ################################################################################
45 def process_dir (arg, dirname, filenames):
46 global waste, db_files, excluded;
48 if string.find(dirname, '/disks-') != -1 or string.find(dirname, 'upgrade-') != -1:
50 # hack; can't handle .changes files
51 if string.find(dirname, 'proposed-updates') != -1:
53 for name in filenames:
54 filename = os.path.abspath(dirname+'/'+name);
55 filename = string.replace(filename, 'potato-proposed-updates', 'proposed-updates');
56 if os.path.isfile(filename) and not os.path.islink(filename) and not db_files.has_key(filename) and not excluded.has_key(filename):
57 waste = waste + os.stat(filename)[stat.ST_SIZE];
60 ################################################################################
65 print "Building list of Database files...";
67 q = projectB.query("SELECT l.path, f.filename FROM files f, location l WHERE f.location = l.id")
72 filename = os.path.abspath(i[0] + i[1]);
73 db_files[filename] = "";
74 if os.access(filename, os.R_OK) == 0:
75 utils.warn("'%s' doesn't exist." % (filename));
77 file = utils.open_file(Cnf["Dir::OverrideDir"]+'override.unreferenced');
78 for filename in file.readlines():
79 filename = filename[:-1];
80 excluded[filename] = "";
82 print "Checking against existent files...";
84 os.path.walk(Cnf["Dir::RootDir"]+'dists/', process_dir, None);
87 print "%s wasted..." % (utils.size_type(waste));
89 ################################################################################
94 for component in Cnf.SubTree("Component").List():
95 if component == "mixed":
97 component = string.lower(component);
98 list_filename = '%s%s_%s_source.list' % (Cnf["Dir::ListsDir"], suite, component);
99 list_file = utils.open_file(list_filename);
100 for line in list_file.readlines():
103 utils.parse_changes(file, 1);
104 except utils.invalid_dsc_format_exc, line:
105 utils.warn("syntax error in .dsc file '%s', line %s." % (file, line));
109 utils.warn("Found %s invalid .dsc files." % (count));
111 ################################################################################
113 def check_override():
114 for suite in [ "stable", "unstable" ]:
116 print "-------------"
118 suite_id = db_access.get_suite_id(suite);
119 q = projectB.query("""
120 SELECT DISTINCT b.package FROM binaries b, bin_associations ba
121 WHERE b.id = ba.bin AND ba.suite = %s AND NOT EXISTS
122 (SELECT * FROM override o WHERE o.suite = %s AND o.package = b.package)"""
123 % (suite_id, suite_id));
125 q = projectB.query("""
126 SELECT DISTINCT s.source FROM source s, src_associations sa
127 WHERE s.id = sa.source AND sa.suite = %s AND NOT EXISTS
128 (SELECT * FROM override o WHERE o.suite = %s and o.package = s.source)"""
129 % (suite_id, suite_id));
132 ################################################################################
134 # Ensure that the source files for any given package is all in one
135 # directory so that 'apt-get source' works...
137 def check_source_in_one_dir():
138 # Not the most enterprising method, but hey...
140 q = projectB.query("SELECT id FROM source;");
141 for i in q.getresult():
143 q2 = projectB.query("""
144 SELECT l.path, f.filename FROM files f, dsc_files df, location l WHERE df.source = %s AND f.id = df.file AND l.id = f.location"""
149 for j in q2.getresult():
150 filename = j[0]+j[1];
151 path = os.path.dirname(filename);
154 first_filename = filename;
155 elif first_path != path:
156 symlink = path + '/' + os.path.basename(first_filename);
157 if not os.path.exists(symlink):
159 print "WOAH, we got a live one here... %s [%s] {%s}" % (filename, source_id, symlink);
161 broken_count = broken_count + 1;
162 print "Found %d source packages where the source is not all in one directory." % (broken_count);
164 ################################################################################
167 print "Getting file information from database...";
168 q = projectB.query("SELECT l.path, f.filename, f.md5sum, f.size FROM files f, location l WHERE f.location = l.id")
171 print "Checking file md5sums & sizes...";
173 filename = os.path.abspath(i[0] + i[1]);
177 file = utils.open_file(filename);
179 utils.warn("can't open '%s'." % (filename));
181 md5sum = apt_pkg.md5sum(file);
182 size = os.stat(filename)[stat.ST_SIZE];
183 if md5sum != db_md5sum:
184 utils.warn("**WARNING** md5sum mismatch for '%s' ('%s' [current] vs. '%s' [db])." % (filename, md5sum, db_md5sum));
186 utils.warn("**WARNING** size mismatch for '%s' ('%s' [current] vs. '%s' [db])." % (filename, size, db_size));
190 ################################################################################
192 # Check all files for timestamps in the future; common from hardware
193 # (e.g. alpha) which have far-future dates as their default dates.
197 def Ent(Kind,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor):
200 if MTime > current_time:
201 future_files[current_file] = MTime;
202 print "%s: %s '%s','%s',%u,%u,%u,%u,%u" % (current_file, Kind,Name,Link,Mode,UID,GID,Size, MTime);
204 def check_timestamps():
207 q = projectB.query("SELECT l.path, f.filename FROM files f, location l WHERE f.location = l.id AND f.filename ~ '.deb$'")
212 filename = os.path.abspath(i[0] + i[1]);
213 if os.access(filename, os.R_OK):
214 file = utils.open_file(filename);
215 current_file = filename;
216 sys.stderr.write("Processing %s.\n" % (filename));
217 apt_inst.debExtract(file,Ent,"control.tar.gz");
219 apt_inst.debExtract(file,Ent,"data.tar.gz");
221 print "Checked %d files (out of %d)." % (count, len(db_files.keys()));
223 ################################################################################
226 global Cnf, projectB, db_files, waste, excluded;
228 Cnf = utils.get_conf()
230 apt_pkg.ParseCommandLine(Cnf,[],sys.argv);
231 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
232 db_access.init(Cnf, projectB);
235 #check_source_in_one_dir();
241 #######################################################################################
243 if __name__ == '__main__':