1 # Lab -- Perl laboratory functions for lintian
4 # Copyright (C) 1998-2004 Various authors
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, you can find it on the World Wide
18 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
19 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
30 # Quiet "Name "main::LINTIAN_ROOT" used only once"
31 # The variables comes from 'lintian'
32 () = ($main::LINTIAN_ROOT, $main::verbose, $main::debug);
34 my $LINTIAN_ROOT = $main::LINTIAN_ROOT;
36 # Can also be more precise later on (only verbose with lab actions) but for
37 # now this will do --Jeroen
38 my $verbose = $main::verbose;
39 my $debug = $main::debug;
42 my ( $class, $dir, $dist ) = @_;
47 $self->setup( $dir, $dist );
55 return unless $self->{dir};
56 return -d "$self->{dir}/binary"
57 && -d "$self->{dir}/udeb"
58 && -d "$self->{dir}/source"
59 && -d "$self->{dir}/info";
63 my ( $self, $dir, $dist ) = @_;
66 $self->{mode} = 'static';
68 $self->{dist} = $dist;
70 $self->{mode} = 'temporary';
76 if ($self->setup_force( $dir, $dist )) {
82 fail("cannot create lab directory $dir");
92 unless ( $self->{mode} eq 'static' and $self->{dir} ) {
93 print STDERR "no laboratory specified (need to define LINTIAN_LAB)";
97 return $self->setup_force( $self->{dir}, $self->{dist} );
102 my ( $self, $dir, $dist ) = @_;
106 print "N: Setting up lab in $dir ...\n" if $verbose;
108 # create lab directory
109 # (Note, that the mode 0777 is reduced by the current umask.)
110 unless (-d $dir && ( $self->{mode} eq 'static' )) {
111 mkdir($dir,0777) or return 0;
114 # create base directories
115 for my $subdir (qw( binary source udeb info )) {
116 my $fulldir = "$dir/$subdir";
117 if (not -d $fulldir) {
118 mkdir($fulldir, 0777)
119 or fail("cannot create lab directory $fulldir");
123 # Just create empty files if they don't already exist. If they do already
124 # exist, we need to keep the old files so that the list-* unpack programs
125 # can analyze what changed.
126 for my $pkgtype (qw( binary source udeb )) {
127 if (not -f "$dir/info/$pkgtype-packages") {
128 _touch("$dir/info/$pkgtype-packages")
129 or fail("cannot create $pkgtype package list");
134 $ENV{'LINTIAN_LAB'} = $dir;
135 $self->populate_with_dist( $dist );
140 sub populate_with_dist {
141 my ( $self, $dist ) = @_;
143 return 0 unless $dist;
144 return 0 unless $self->{dir};
146 print STDERR "spawning list-binpkg, list-udebpkg and list-srcpkg since LINTIAN_DIST=$dist\n" if ($debug >= 2);
148 my $v = $verbose ? '-v' : '';
150 spawn("$LINTIAN_ROOT/unpack/list-binpkg",
151 "$self->{dir}/info/binary-packages", $v) == 0
152 or fail("cannot create binary package list");
153 spawn("$LINTIAN_ROOT/unpack/list-srcpkg",
154 "$self->{dir}/info/source-packages", $v) == 0
155 or fail("cannot create source package list");
156 spawn("$LINTIAN_ROOT/unpack/list-udebpkg",
157 "$self->{dir}/info/udeb-packages", $v) == 0
158 or fail("cannot create udeb package list");
166 unless ( $self->{mode} eq 'static' and $self->{dir} ) {
167 print STDERR "warning: no laboratory specified (need to define LINTIAN_LAB)";
171 return $self->delete_force;
177 return 1 unless $self->{mode} eq 'temporary';
179 return $self->delete_force;
182 # Remove is apparantly some reserved name...
186 return 0 unless $self->{dir};
188 print "N: Removing $self->{dir} ...\n" if $verbose;
190 # since we will chdir in a moment, make the path of the lab absolute
191 unless ( $self->{dir} =~ m,^/, ) {
193 $self->{dir} = Cwd::getcwd() . "/$self->{dir}";
196 # chdir to root (otherwise, the shell will complain if we happen
197 # to sit in the directory we want to delete :)
200 # does the lab exist?
201 unless (-d $self->{dir}) {
203 print STDERR "warning: cannot remove lab in directory $self->{dir} ! (directory does not exist)\n";
207 # sanity check if $self->{dir} really points to a lab :)
208 unless (-d "$self->{dir}/binary") {
209 # binary/ subdirectory does not exist--empty directory?
210 my @t = glob("$self->{dir}/*");
212 # yes, empty directory--skip it
215 # non-empty directory that does not look like a lintian lab!
216 print STDERR "warning: directory $self->{dir} does not look like a lab! (please remove it yourself)\n";
222 if (spawn('rm', '-rf', '--',
223 "$self->{dir}/binary",
224 "$self->{dir}/source",
226 "$self->{dir}/info") != 0) {
227 print STDERR "warning: cannot remove lab directory $self->{dir} (please remove it yourself)\n";
231 if ($self->{mode} eq 'temporary') {
232 if (rmdir($self->{dir}) != 1) {
233 print STDERR "warning: cannot remove lab directory $self->{dir} (please remove it yourself)\n";
242 # create an empty file
243 # --okay, okay, this is not exactly what `touch' does :-)
245 open(T, '>', $_[0]) or return 0;
246 close(T) or return 0;
254 # vim: ts=4 sw=4 noet