Prechádzať zdrojové kódy

Add a new -m flag which enables checks for MOVED, UIDs, and GIDs. This flag
is disabled by default, but can be enabled with -c, -C, or -A.

Submitted by: hrs

marcus 14 rokov pred
rodič
commit
d730f127d0
2 zmenil súbory, kde vykonal 82 pridanie a 11 odobranie
  1. 6 4
      portlint.1
  2. 76 7
      portlint.pl

+ 6 - 4
portlint.1

@@ -4,7 +4,7 @@
 .\" Copyright (c) 1997 by Jun-ichiro Hagino <itojun@itojun.org>.
 .\" All Rights Reserved.  Absolutely no warranty.
 .\"
-.Dd May 30, 2006
+.Dd April 1, 2010
 .Dt PORTLINT 1
 .Sh NAME
 .Nm portlint
@@ -62,6 +62,8 @@ appropriate).  This option is disabled if
 is specified.
 .It Fl h
 Show the summary of command line options, then exit.
+.It Fl m
+Adds checks for $PORTSDIR/MOVED, $PORTSDIR/UIDs, and $PORTSDIR/GIDs.
 .It Fl v
 Be verbose.
 Show the progress report for items that are being checked.
@@ -71,7 +73,7 @@ Nit pick about use of spaces.
 Turn on all additional checks.
 .It Fl C
 Pedantic committer flag.  This is equivalent to
-.Fl abct .
+.Fl abcmt .
 .It Fl N
 New port flag.
 Adds several checks specific to newly submitted port.
@@ -97,7 +99,7 @@ If omitted, check will be performed over the current directory.
 .El
 .Sh DIAGNOSTICS
 Messages will be sent to standard output, not standard error output.
-.Bl -tag -width WARN: foobaa
+.Bl -tag -width "WARN: foobaa"
 .It FATAL: ...
 This type of error message suggests that there is some fatal error
 in the port directory.
@@ -162,7 +164,7 @@ on
 can be overriden by setting the
 .Va PORTSDIR
 environment variable.
-
+.El
 .Sh AUTHORS
 .An Joe Marcus Clarke Aq marcus@FreeBSD.org
 .An Michael Haro Aq mharo@FreeBSD.org

+ 76 - 7
portlint.pl

@@ -29,11 +29,11 @@ use IPC::Open2;
 use POSIX qw(strftime);
 
 sub perror($$$$);
-our ($opt_a, $opt_A, $opt_b, $opt_C, $opt_c, $opt_g, $opt_h, $opt_t, $opt_v, $opt_M, $opt_N, $opt_B, $opt_V, @ALLOWED_FULL_PATHS, @MASTERSITES_WHITELIST);
+our ($opt_a, $opt_A, $opt_b, $opt_C, $opt_c, $opt_g, $opt_h, $opt_m, $opt_t, $opt_v, $opt_M, $opt_N, $opt_B, $opt_V, @ALLOWED_FULL_PATHS, @MASTERSITES_WHITELIST);
 
 my ($err, $warn);
 my ($extrafile, $parenwarn, $committer, $verbose, $usetabs, $newport,
-	$grouperrs);
+	$grouperrs, $checkmfiles);
 my $contblank;
 my $portdir;
 my $makeenv = "";
@@ -42,6 +42,7 @@ my %errcache = ();
 
 $err = $warn = 0;
 $extrafile = $parenwarn = $committer = $verbose = $usetabs = $newport = 0;
+$checkmfiles = 0;
 $contblank = 1;
 $portdir = '.';
 
@@ -98,16 +99,17 @@ my $re_lang_short = '(' . join('|', @lang_short) . ')-';
 my ($prog) = ($0 =~ /([^\/]+)$/);
 sub usage {
 	print STDERR <<EOF;
-usage: $prog [-AabCcghvtN] [-M ENV] [-B#] [port_directory]
+usage: $prog [-AabCcghmvtN] [-M ENV] [-B#] [port_directory]
 	-a	additional check for scripts/* and pkg-*
-	-A	turn on all additional checks (equivalent to -abcNt)
+	-A	turn on all additional checks (equivalent to -abcmNt)
 	-b	warn \$(VARIABLE)
-	-c	committer mode
-	-C	pedantic committer mode (equivalent to -abct)
+	-c	committer mode (implies -m)
+	-C	pedantic committer mode (equivalent to -abcmt)
 	-g  group errors together to avoid duplication (disabled if -v is specified)
 	-h	show summary of command line options
 	-v	verbose mode
 	-t	nit pick about use of spaces
+	-m	check \${PORTSDIR}/MOVED, UIDs, and GIDs files
 	-N	writing a new port
 	-V	print the version and exit
 	-M ENV	set make variables to ENV (ex. PORTSDIR=/usr/ports.work)
@@ -121,7 +123,7 @@ sub version {
 	exit $major;
 }
 
-getopts('AabCcghtvB:M:NV');
+getopts('AabCcghmtvB:M:NV');
 
 &usage if $opt_h;
 &version if $opt_V;
@@ -130,6 +132,7 @@ $parenwarn = 1 if $opt_b || $opt_A || $opt_C;
 $committer = 1 if $opt_c || $opt_A || $opt_C;
 $verbose = 1 if $opt_v;
 $grouperrs = 1 if $opt_g && !$opt_v;
+$checkmfiles = 1 if $opt_m || $opt_c || $opt_A || $opt_C;
 $newport = 1 if $opt_N || $opt_A;
 $usetabs = 1 if $opt_t || $opt_A || $opt_C;
 $contblank = $opt_B if $opt_B;
@@ -159,6 +162,9 @@ foreach my $i (@osdep) {
 # The PORTSDIR environment variable overrides our defaults.
 $portsdir = $ENV{PORTSDIR} if ( defined $ENV{'PORTSDIR'} );
 $ENV{'PL_CVS_IGNORE'} //= '';
+my $mfile_moved = "${portsdir}/MOVED";
+my $mfile_uids = "${portsdir}/UIDs";
+my $mfile_gids = "${portsdir}/GIDs";
 
 if ($verbose) {
 	print "OK: config: portsdir: \"$portsdir\" ".
@@ -288,6 +294,14 @@ if ($extrafile) {
 		}
 	}
 }
+if ($checkmfiles) {
+    foreach my $i ($mfile_moved, $mfile_uids, $mfile_gids) {
+		next if (! -T $i);
+		next if (defined $checker{$i});
+		push(@checker, $i);
+		$checker{$i} = \&checkmfile;
+	}
+}
 foreach my $i (<$makevar{PATCHDIR}/patch-*>) {
 	next if (! -T $i);
 	next if (defined $checker{$i});
@@ -1015,7 +1029,62 @@ sub checkplist {
 
 	close(IN);
 }
+#
+# ${PORTSDIR}/MOVED, UIDs, GIDs files
+#
+sub checkmfile {
+	my ($file) = @_;
+	my $line = 0;
+    my $format;
+    my @entries;
+    my @sorted;
+	my $dosort;
+
+	if ($file =~ m/MOVED$/) {
+		$format = '^[^|]*\|[^|]*\|[^|]*\|[^|]*$';
+		$dosort = 0;
+    } elsif ($file =~ m/UIDs$/) {
+		$format = '^[^:]+:\*:[0-9]+:[0-9]+::0:0:[^:]+:[^:]+:[^:]+$';
+		$dosort = 1;
+    } elsif ($file =~ m/GIDs$/) {
+		$format = '^[^:]+:\*:[0-9]+:[^:]*$';
+		$dosort = 1;
+	} else {
+		&perror("FATAL", $file, -1, "Internal error. ".
+			"Invalid name for mfiles.");
+    }
 
+	open(IN, "<$file") || return 0;
+	while (<IN>) {
+		chomp;
+		$line++;
+		next if (m,^\s*#,);
+
+		if (!m,${format},) {
+			&perror("FATAL", $file, -1,
+					"malformed line at ".
+					"${line}.\n => $_");
+		} else {
+			push @entries, "$line:$_";
+			next;
+		}
+	}
+    if ($dosort) {
+		my $errline;
+		@sorted = sort {(split /:/, $a)[3] <=> (split /:/, $b)[3] } @entries;
+
+		for (my $n = 0; $n < @entries; $n++) {
+			if (!defined($sorted[$n]) or
+				$entries[$n] ne $sorted[$n]) {
+					($line, $errline) = ($entries[$n] =~ m/([0-9]+):(.*)/);
+					&perror("WARN", $file, -1,
+							"malformed sorting order at " .
+							"${line}.\n => $errline");
+			}
+       }
+	}
+	close(IN);
+}
 #
 # misc files
 #