r10330 - /man-cgi/extractor/manpage-extractor.pl
Author: jfs
Date: Wed Nov 6 20:59:14 2013
New Revision: 10330
URL: http://svn.debian.org/wsvn/?sc=1&rev=10330
Log:
- Improved error handling to ensure that the temporary files created get removed
- Extract files always from arch: all packages, since these apply to all architectures
Modified:
man-cgi/extractor/manpage-extractor.pl
Modified: man-cgi/extractor/manpage-extractor.pl
URL: http://svn.debian.org/wsvn/man-cgi/extractor/manpage-extractor.pl?rev=10330&op=diff
==============================================================================
--- man-cgi/extractor/manpage-extractor.pl (original)
+++ man-cgi/extractor/manpage-extractor.pl Wed Nov 6 20:59:14 2013
@@ -157,7 +157,7 @@
# Note, this means that we will only analyse one binary package
# of all the different architectures available
- if ( $arch ne $ARCHITECTURE ) {
+ if ( $arch ne $ARCHITECTURE && $arch ne "all" ) {
print "INFO: Skipping package file (architecture '$arch', we want '$ARCHITECTURE')\n" if $debug;
return 0;
}
@@ -186,7 +186,11 @@
print "INFO: Extracting manpages of $packagename version '$version' in $mandir\n";
# You can either do a search in the binary files:
if ( $EXTENSION eq "deb" ) {
- if ( extract_manpages($WORKDIR, $file, $mandir) ) {
+ my $result = extract_manpages($WORKDIR, $file, $mandir) ;
+ if ( $result == 1 ) {
+ print "WARNING: There was an error extracting manpages from $file\n";
+ }
+ if ( $result == 2 ) {
print "WARNING: No manpages found.\n";
# Optionally, remove the directory, there were no manpages there
# if ( -e "$mandir" ) {
@@ -206,12 +210,14 @@
sub extract_manpages {
my ($wdir, $package, $dstdir) = @_;
# Looks for manpages in the sources
+
+ # By default we exit with an error
my $result = 1;
+
# Temporary file for dpkg
- my $tempfileh = new File::Temp ( Template => "DPKG-DEB.XXXXXX", DIR => $WORKDIR, SUFFIX => ".tmp" ) or die "Cannot create temporary file: $!" ;
-
- my $tempfile = $tempfileh->filename;
-
+ my ($tempfileh, $tempfile) = new File::Temp ( Template => "DPKG-DEB.XXXXXX", DIR => "$WORKDIR", SUFFIX => ".tmp" ) or die "Cannot create temporary file: $!" ;
+
+ # Call dpkg-deb to obtain the package contents
# TODO: notice that this is _NOT_ secure there are multiple entry
# points for command injection, rewrite this in Perl?
my $command="dpkg-deb --fsys-tarfile $package >$tempfile";
@@ -225,25 +231,44 @@
} else {
printf STDERR "ERROR: child exited with value %d\n", $? >> 8;
}
- die "Error running '$command'";
- }
- $command="tar -C $wdir -xf $tempfile usr/share/man ./usr/share/man usr/X11R6/man ./usr/X11R6/man 2>/dev/null";
- system "$command";
- printf STDERR "ERROR: tar exited with value %d\n", $? >> 8 if $? != 0 && $? != ( 2 << 8 );
-# Note we skip exit value '2' which happens when tar does not find any file according to specification
-
-# If we have a directory then move all the files in it
-# otherwise, we will return with an error
- if ( -e "$wdir/usr/" ) {
- system "mv $wdir/* $dstdir" || die "Error moving directory: $?";
- $result = 0;
- }
-
-# Clean up temporary files
+ printf STDERR "Error running '$command'";
+ $result = 1;
+ } else {
+
+ # IF we have a tarfile we extract anything that is within the normal
+ # manpages directory.
+ # BUG: Some manpages are managed through alternatives and will not get
+ # extracted here
+ $command="tar -C $wdir -xf $tempfile usr/share/man ./usr/share/man usr/X11R6/man ./usr/X11R6/man 2>/dev/null";
+ system "$command";
+
+ if ( $? != 0 ) {
+ printf STDERR "ERROR: tar exited with value %d\n", $? >> 8 if $? != 0 && $? != ( 2 << 8 );
+ # Note we skip exit value '2' which happens when tar does not find any file according to specification
+ }
+
+ # If we have a directory then move all the files in it
+ # otherwise, we will return with an error
+ if ( -e "$wdir/usr/" ) {
+ system "mv $wdir/* $dstdir" ;
+ if ( $? != 0 ) {
+ printf STDERR "Error moving directory $wdir to $dstdir: $?";
+ $result = 1;
+ } else {
+ # IF we got there everything worked fine and we have manpages in the archive
+ $result = 0;
+ }
+ } else {
+ # This package has no manual pages
+ $result = 2;
+ }
+
+ }
+
+# Clean up temporary files before returning
unlink $tempfile;
close $tempfileh;
-
-# And return
+# And return with our result
return $result;
}
Reply to: