3
# Check the integrity of an archive via it's indices files
4
# Copyright (C) 2006 James Troup <james.troup@canonical.com>
6
################################################################################
17
################################################################################
20
ArchiveRoot = "/srv/launchpad.net/ubuntu-archive/ubuntu/"
23
################################################################################
26
sys.stderr.write("E: %s\n" % (msg))
28
################################################################################
30
def check_file(filename, md5sum_expected, size_expected):
33
# Check existence/readability
34
if os.access(filename, os.R_OK) == 0:
35
if os.path.exists(filename):
36
error("%s could not be read (permission denied)" \
39
error("%s is missing" % (filename))
43
filehandle = open(filename)
44
md5sum_found = apt_pkg.md5sum(filehandle)
45
if md5sum_found != md5sum_expected:
46
error("%s failed md5sum check ('%s' vs '%s')" \
47
% (filename, md5sum_expected, md5sum_found))
50
size_found = os.stat(filename)[stat.ST_SIZE]
51
size_expected = int(size_expected)
52
if size_found != size_expected:
53
error("%s failed size check (expected: %d, got: %d)" \
54
% (filename, size_expected, size_found))
61
################################################################################
63
def validate_sources(sources_filename, suite, component):
66
sys.stdout.write("Checking %s/%s/source: " % (suite, component))
68
# apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
69
temp_filename = dak_utils.temp_filename()
70
(result, output) = commands.getstatusoutput("gunzip -c %s > %s" \
74
sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
76
sources = open(temp_filename)
77
Sources = apt_pkg.ParseTagFile(sources)
79
directory = Sources.Section.Find('Directory')
80
files = Sources.Section.Find('Files')
81
for i in files.split('\n'):
82
(md5sum_expected, size_expected, name) = i.split()
83
filename = os.path.join(ArchiveRoot, directory, name)
84
check_file(filename, md5sum_expected, size_expected)
85
sys.stdout.write("done.\n")
88
os.unlink(temp_filename)
90
################################################################################
92
def validate_packages(packages_filename, suite, component, architecture):
96
sys.stdout.write("Checking %s/%s/%s: " % (suite, component, architecture))
98
# apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
99
temp_filename = dak_utils.temp_filename()
100
(result, output) = commands.getstatusoutput("gunzip -c %s > %s"
101
% (packages_filename,
104
sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
106
packages = open(temp_filename)
107
Packages = apt_pkg.ParseTagFile(packages)
108
while Packages.Step():
109
md5sum_expected = Packages.Section.Find('MD5sum')
110
size_expected = Packages.Section.Find('Size')
111
filename = Packages.Section.Find('Filename')
112
filename = os.path.join(ArchiveRoot, filename)
113
check_file(filename, md5sum_expected, size_expected)
115
sys.stdout.write("done.\n")
118
os.unlink(temp_filename)
120
################################################################################
122
def _process_dir(_, dirname, filenames):
125
for filename in filenames:
126
if filename == "Packages.gz" or filename == "Sources.gz":
127
split = dirname.split('/')
128
if split[-2] == "debian-installer":
129
(suite, component, _, architecture) = split[-4:]
131
(suite, component, architecture) = split[-3:]
132
architecture = architecture.replace("binary-", "")
133
full_filename = os.path.join(dirname, filename)
134
if architecture == "source":
135
validate_sources(full_filename, suite, component)
137
validate_packages(full_filename, suite, component, architecture)
139
################################################################################
147
os.path.walk(os.path.join(ArchiveRoot, "dists"),
152
################################################################################
154
if __name__ == '__main__':