Skip to content

Instantly share code, notes, and snippets.

@melo
Created August 3, 2016 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melo/17fce15abbe442717d1c60d5efa5fb02 to your computer and use it in GitHub Desktop.
Save melo/17fce15abbe442717d1c60d5efa5fb02 to your computer and use it in GitHub Desktop.
Carton local dir inspection tool
#!/usr/bin/env perl
#
# Checks "provides" list in install.json files with the actual files
# installed by Carton on your local dir
#
use strictures 2;
use File::Find;
use Path::Tiny;
use JSON::MaybeXS 'decode_json';
use Config;
my $local = shift @ARGV;
die "Usage: sanity.pl <carton_local_dir>\n" unless $local and -d $local;
my @installed;
my $wanted = sub { push @installed, $File::Find::name if $File::Find::name =~ m{/install\.json$} };
File::Find::find({ no_chdir => 1, wanted => $wanted }, $local);
my %known_files;
for my $meta (@installed) {
my $info = decode_json(path($meta)->slurp);
$known_files{"$_.pm"}++ for map { s/::/\//g; $_ } keys %{ $info->{provides} || {} };
}
my $re = qr!^$local/lib/perl5(?:/$Config{archname})?/(.+)!;
my $check = sub {
return unless $File::Find::name =~ m/\.pm$/;
my ($key) = $File::Find::name =~ m!$re!;
die "unmatched $File::Find::name\n" unless $key;
return if exists $known_files{$key};
print "missing $key\n";
};
File::Find::find({ no_chdir => 1, wanted => $check }, $local);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment