Created
August 3, 2016 16:33
-
-
Save melo/17fce15abbe442717d1c60d5efa5fb02 to your computer and use it in GitHub Desktop.
Carton local dir inspection tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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