Sindbad~EG File Manager

Current Path : /usr/bin/
Upload File :
Current File : //usr/bin/dh_missing

#!/usr/bin/perl

=head1 NAME

dh_missing - check for missing files

=cut

use strict;
use warnings;
use Debian::Debhelper::Dh_Lib;

our $VERSION = DH_BUILTIN_VERSION;

=head1 SYNOPSIS

B<dh_missing> [B<-X>I<item>] [B<--sourcedir=>I<dir>] [S<I<debhelper options>>]

=head1 DESCRIPTION

B<dh_missing> compares the list of installed files with the files in
the source directory. If any of the files (and symlinks) in the source
directory were not installed to somewhere, it will warn on stderr
about that (B<--list-missing>) or fail (B<--fail-missing>).  Please
note that without either of these options, B<dh_missing> will silently
do nothing.

This may be useful if you have a large package and want to make sure that
you don't miss installing newly added files in new upstream releases.

Remember to test different kinds of builds (dpkg-buildpackage -A/-B/...) as
you may experience varying results when only a subset of the packages are
built.

=head1 FILES

=over 4

=item debian/not-installed

List the files that are deliberately not installed in I<any> binary
package.  Paths listed in this file are ignored by B<dh_missing>.
However, it is B<not> a method to exclude files from being installed
by any of the debhelper tool.  If you want a tool to not install a
given file, please use its B<--exclude> option (where available).

B<dh_missing> will expand wildcards in this file (since debhelper 11.1).
Wildcards without matches will be ignored.

=back

=head1 OPTIONS

=over 4

=item B<--list-missing>

Warn on stderr about source files not installed to somewhere.

Note that files that are excluded from being moved via the B<-X> option are not
warned about.

This is the default in compat 12 and later.

=item B<--fail-missing>

This option is like B<--list-missing>, except if a file was missed, it will
not only list the missing files, but also fail with a nonzero exit code.

=back

=cut

init(options => {
	"list-missing" => \$dh{LIST_MISSING},
	"fail-missing" => \$dh{FAIL_MISSING},
	"sourcedir=s" => \$dh{SOURCEDIR},
});

my (@installed, %helpers);

my $srcdir = '.';
$srcdir = $dh{SOURCEDIR} if defined $dh{SOURCEDIR};

# --list-missing is the default in compat 12+
$dh{LIST_MISSING} = 1 if !$dh{FAIL_MISSING} && !compat(11);

if (!$dh{LIST_MISSING} && !$dh{FAIL_MISSING}) {
	exit 0;
}

# . as srcdir makes no sense, so this is a special case.
if ($srcdir eq '.') {
	$srcdir='debian/tmp';
}

if (! -d $srcdir) {
	# If there was no explicit source directory, then we do not care
	# if it is missing.
	exit(0) if not defined $dh{SOURCEDIR};

	if (scalar(getpackages()) == 1 && defined($dh{SOURCEDIR})) {
		warning("$srcdir does not exist and there is only binary package.");
		warning("Assuming everything is installed directly into the package directory.");
		exit(0);
	}
	if (compat(10)) {
		# Prevent "dh $@ --list-missing --destdir=... ..." from failing in compat 10.
		warning("Cannot check if installation is missing files: $srcdir does not exist");
		exit(0);
	} else {
		error("Cannot check if installation is missing files: $srcdir does not exist");
	}
}

for my $file (glob('debian/.debhelper/generated/*/installed-by-*')) {
	my ($target_pkg, $helper) = ('unknown', 'unknown');
	my $had_files = 0;
	my %seen;
	if ($file =~ m@.*/([^/]+)/installed-by-(.*)@) {
		($target_pkg, $helper) = ($1, $2);
	}

	open(my $fh, '<', $file) or die "could not open $file: $!";
	while (my $line = <$fh>) {
		chomp($line);
		next if $line =~ m/^\s*$/;
		next if $seen{$line}++; # Ignore duplicates
		$had_files++;
		push(@installed, $line);
	}
	$helpers{$helper}{$target_pkg} = $had_files;
	close($fh);
}

my @missing;
if ( -f 'debian/not-installed') {
	my @not_installed = filearray('debian/not-installed');
	for my $pattern (@not_installed) {
		my @matches;
		# Add an explicit d/tmp if absent as there is no point in
		# looking outside the debian staging directory
		$pattern =~ s:^\s*:debian/tmp/: unless $pattern =~ m:^\s*debian/tmp/:;
		@matches = glob_expand(['.'], \&glob_expand_error_handler_silently_ignore, $pattern);
		if (@matches) {
			# Assume classify them as installed
			push(@installed, @matches);
		} else {
			# Assume it is not a pattern and classify it as installed
			push(@installed, $pattern);
		}
	}

	push(@installed, @not_installed);
}
my $installed=join("|", map {
	# Kill any extra slashes, for robustness.
	y:/:/:s;
	s:/+$::;
	s:^(\./)*::;
	"\Q$_\E\/.*|\Q$_\E";
} @installed);
$installed=qr{^($installed)$};

# Lazy load File::Find
require File::Find;

File::Find::find(sub {
	# Lazy loading of File::Find makes perl think that File::Find::dir is only used once
	# and we might have typo'ed something
	no warnings qw(once);
	-f || -l || return;
	$_="$File::Find::dir/$_";
	if (! /$installed/ && ! excludefile($_)) {
		my $file=$_;
		$file=~s/^\Q$srcdir\E\///;
		push @missing, $file;
	}
}, $srcdir);
if (@missing) {
	warning "$_ exists in $srcdir but is not installed to anywhere" foreach @missing;
	nonquiet_print("The following debhelper tools have reported what they installed (with files per package)");
	for my $helper (sort(keys(%helpers))) {
		my $pkg_info = $helpers{$helper};
		my @results;
		for my $pkg (sort(keys(%{$pkg_info}))) {
			my $no = $pkg_info->{$pkg};
			push(@results, "${pkg} (${no})")
		}
		nonquiet_print(" * ${helper}: " . join(', ', @results));
	}
	nonquiet_print("If the missing files are installed by another tool, please file a bug against it.");
	nonquiet_print('When filing the report, if the tool is not part of debhelper itself, please reference the');
	nonquiet_print('"Logging helpers and dh_missing" section from the "PROGRAMMING" guide for debhelper (10.6.3+).');
	nonquiet_print('  (in the debhelper package: /usr/share/doc/debhelper/PROGRAMMING.gz)');
	nonquiet_print("Be sure to test with dpkg-buildpackage -A/-B as the results may vary when only a subset is built");
	nonquiet_print("For a short-term work-around: Add the files to debian/not-installed");
	if ($dh{FAIL_MISSING}) {
		error("missing files, aborting");
	}
}

=head1 SEE ALSO

L<debhelper(7)>

This program is a part of debhelper.

=head1 AUTHOR

Michael Stapelberg <stapelberg@debian.org>

=cut

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists