Skip to content

Commit

Permalink
Item13844: MANIFEST fixes for 1.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
gac410 committed Nov 12, 2015
1 parent 8040a54 commit d55730b
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 44 deletions.
5 changes: 5 additions & 0 deletions core/lib/Foswiki/Contrib/core/MANIFEST
Expand Up @@ -818,6 +818,11 @@ lib/Foswiki/Store/VC/Handler.pm 0444
lib/Foswiki/Store/VC/RcsLiteHandler.pm 0444
lib/Foswiki/Store/VC/RcsWrapHandler.pm 0444
lib/Foswiki/Store/VC/Store.pm 0444
lib/Foswiki/Tables/Cell.pm 0444
lib/Foswiki/Tables/Parser.pm 0444
lib/Foswiki/Tables/Reader.pm 0444
lib/Foswiki/Tables/Row.pm 0444
lib/Foswiki/Tables/Table.pm 0444
lib/Foswiki/Templates.pm 0444
lib/Foswiki/Time.pm 0444
lib/Foswiki/UI.pm 0444
Expand Down
188 changes: 144 additions & 44 deletions core/tools/check_manifest.pl
@@ -1,64 +1,164 @@
#! /usr/bin/perl
#! /usr/bin/env perl

use strict;
use warnings;

# cruise back up the tree until we find lib and data subdirs
require Cwd;
use Cwd;
use File::Spec;
use File::Find;

my $manifest = 'MANIFEST';
my $manifest = shift || 'MANIFEST';
my @skip =
qw(tools/develop tools/githooks tools/pkg tools/benchmark tools/distro test working logs MANIFEST DEPENDENCIES build\.pl PREINSTALL TIDY .*?\.psd .*?\.xcf \.gitignore);
my $cvs = 'subversion';
my $skipPattern = join( '|', @skip );

#unless (-f $manifest) {
# File::Find::find( sub { /^MANIFEST\z/ && ( $manifest = $File::Find::name )
# }, "$root/lib/TWiki" );
#}
die "No such MANIFEST $manifest" unless -e $manifest;
#print "SKIPPING $skipPattern\n";
my @lost; # Files on disk not in MANIFEST
my %man; # Hash of MANIFEST content: file => perm
my %alt; # Hash of alternate version of _src file
my $checkperm = 0;
my @manfiles;

my %man;
# Search the current working directory and its parents
# for a directory called like the first parameter
sub findPathToDir {
my $lookForDir = shift;

open MAN, '<', $manifest or die "Can't open $manifest for reading: $!";
while (<MAN>) {
next if /^!include/;
$man{$1} = 1 if /^(\S+)\s+\d+.*$/;
my @dirlist = File::Spec->splitdir( Cwd::getcwd() );
do {
my $dir = File::Spec->catdir( @dirlist, $lookForDir );
return File::Spec->catdir(@dirlist) if -d $dir;
} while ( pop @dirlist );
return;
}
close MAN;

my @cwd = split( /[\/\\]/, Cwd::getcwd() );
my $root;
# Checks if a file is in the MANIFEST, and removes it
# otherwise, adds it to @lost
sub isFileInManifest {
my ( $root, $file ) = @_;

my $diskfile = "$root/$file";
return if -d $diskfile; # For Subversion
if ( my $mode = delete $man{$file} ) {
my $cmode = ( stat($diskfile) )[2] & 07777;
printf "Permissions for $file differ"
. " in MANIFEST ($mode) and on disk (%lo)\n", $cmode
if ( $checkperm && oct( 0 + $mode ) != $cmode );
}
else {
return if $file =~ m#^(?:$skipPattern)/#; # For git
#print "Checking ($file) against #/(?:$skipPattern)\$# \n";
return if $file =~ m#(?:^|/)(?:$skipPattern)$#; # For git
return if $file =~ m#/TestCases/#;
push @lost, $file;
}

while ( scalar(@cwd) > 1 ) {
$root = join( '/', @cwd );
if ( -d "$root/lib" && -d "$root/data" ) {
last;
# Try to save file alternate versions, just in case
$alt{"$file.gz"}++;
if ( $file =~ /^(.*)_src(\..*)$/ ) {
$alt{"$1$2"}++;
$alt{"$1$2.gz"}++;
}
if ( $file =~ /^(.*)\.uncompressed(\..*)$/ ) {
$alt{"$1$2"}++;
$alt{"$1$2.gz"}++;
}
pop(@cwd);
}

die "Can't find root" unless ( -d "$root/lib" && -d "$root/data" );
# Prints some "helpful" messages
sub help {
print <<"END";
Run this script from a directory with a MANIFEST file, or from a top level of
an extension, or from within an extension, passing the path of the MANIFEST as
first parameter.
my @skip = qw(tools test working logs);
print <<END;
Run this script from anywhere a directory with a MANIFEST file
The script will find and scan MANIFEST and compare the contents with what is
checked in under $cvs. Any differences are reported.
The script will find and scan MANIFEST and compare the contents with
what is checked in under subversion. Any differences are reported.
It will also compare permissions given in the MANIFEST with permissions which
are on disk.
END
print "The ", join( ',', @skip ), " directories are *not* scanned.\n";

my @lost;
my $sk = join( '|', @skip );
foreach my $dir (
grep { -d "$root/$_" }
split( /\n/, `svn ls $root` )
)
{
next if $dir =~ /^($sk)\/$/;
print "Examining $root/$dir\n";
push( @lost,
grep { !$man{$_} && !/\/TestCases\// && !-d "$root/$_" }
map { "$dir$_" }
split( /\n/, `svn ls -R $root/$dir` ) );
print "The " . join( ', ', @skip ) . " directories are *not* scanned.\n";
}

my $root = findPathToDir('lib');
die "Can't find root" unless ( -d "$root/lib" && -d "$root/data" );

unless ( -f $manifest ) {
File::Find::find(
sub {
/^MANIFEST\z/ && ( $manifest = $File::Find::name );
push @manfiles, $manifest if /^MANIFEST\z/;
},
File::Spec->catdir( $root, 'lib' )
);
}
die "No such MANIFEST $manifest" unless -e $manifest;

#foreach my $mf ( @manfiles ) {
# print " .. FOUND $mf \n";
# }

open my $man, '<', $manifest or die "Can't open $manifest for reading: $!";
print "Processing manifest $manifest\n";
while (<$man>) {
next if /^!include/;
$man{$1} = $2 if /^#?(\S+)\s+(\d+)/;
}
close $man;

if ( my $gitdir = findPathToDir('.git') ) {
$cvs = 'git';

#help($cvs);
for my $file ( split /\n/, qx{cd $root && git ls-files} ) {
$file =~ s#^$root/##; # Should never happen, but safer
$file =~ s#^(?:\.\./)*##; # If checking not from top level
isFileInManifest( $root => $file );
}
}
else {
help($cvs);
foreach my $dir (
grep { -d "$root/$_" }
split( /\n/, `svn ls $root` )
)
{
next if $dir =~ m#/(?:$skipPattern)/#o;
print "Examining $root/$dir\n";
for my $file (
map { "$dir$_" }
split( /\n/, `svn ls -R $root/$dir` )
)
{
isFileInManifest( $root => $file );
}
}
}
print "The following files were found in subversion, but are not in MANIFEST\n";
print join( "\n", @lost ), "\n";

if (@lost) {
my $lost = scalar @lost;
print "The following $lost file"
. ( $lost > 1 ? 's' : '' )
. " files were found in $cvs, but are not in MANIFEST:\n";
print join( "\n", @lost, '' );
}

#else {
# print "All files in MANIFEST are checked in.\n";
#}
my @found = sort grep { !delete $alt{$_} } keys %man;
if (@found) {
my $found = scalar @found;
print "The following $found file"
. ( $found > 1 ? 's' : '' )
. " were found in MANIFEST, but not in $cvs:\n";
print join( "\n", @found, '' );
}

#else {
# print "All files in MANIFEST are in $cvs.\n";
#}
25 changes: 25 additions & 0 deletions core/tools/check_manifests.sh
@@ -0,0 +1,25 @@
perl tools/check_manifest.pl
cd ../AutoViewTemplatePlugin && perl ../core/tools/check_manifest.pl
cd ../CompareRevisionsAddOn && perl ../core/tools/check_manifest.pl
cd ../CommentPlugin && perl ../core/tools/check_manifest.pl
cd ../EditTablePlugin && perl ../core/tools/check_manifest.pl
cd ../EmptyPlugin && perl ../core/tools/check_manifest.pl
cd ../FamFamFamContrib && perl ../core/tools/check_manifest.pl
cd ../HistoryPlugin && perl ../core/tools/check_manifest.pl
cd ../InterwikiPlugin && perl ../core/tools/check_manifest.pl
cd ../JSCalendarContrib && perl ../core/tools/check_manifest.pl
cd ../JQueryPlugin && perl ../core/tools/check_manifest.pl
cd ../MailerContrib && perl ../core/tools/check_manifest.pl
cd ../PatternSkin && perl ../core/tools/check_manifest.pl
cd ../PreferencesPlugin && perl ../core/tools/check_manifest.pl
cd ../RenderListPlugin && perl ../core/tools/check_manifest.pl
cd ../SlideShowPlugin && perl ../core/tools/check_manifest.pl
cd ../SmiliesPlugin && perl ../core/tools/check_manifest.pl
cd ../SpreadSheetPlugin && perl ../core/tools/check_manifest.pl
cd ../TablePlugin && perl ../core/tools/check_manifest.pl
cd ../TinyMCEPlugin && perl ../core/tools/check_manifest.pl
cd ../TipsContrib && perl ../core/tools/check_manifest.pl
cd ../TopicUserMappingContrib && perl ../core/tools/check_manifest.pl
cd ../TWikiCompatibilityPlugin && perl ../core/tools/check_manifest.pl
cd ../TwistyPlugin && perl ../core/tools/check_manifest.pl
cd ../WysiwygPlugin && perl ../core/tools/check_manifest.pl

0 comments on commit d55730b

Please sign in to comment.