package System::Introspector::Probe::Packages::Apt;
use Moo;
+use File::Basename;
use System::Introspector::Util qw(
handle_from_command
transform_exceptions
+ output_from_file
+ files_from_dir
);
has apt_lists_dir => (is => 'ro', builder => 1);
has apt_update_after => (is => 'ro', default => sub { 86400 });
has apt_update => (is => 'ro');
-sub _build_apt_lists_dir { '/var/lib/apt/lists' }
+has apt_sources => (is => 'ro', builder => 1);
+has apt_sources_dir => (is => 'ro', builder => 1);
+
+sub _build_apt_lists_dir { '/var/lib/apt/lists' }
+sub _build_apt_sources { '/etc/apt/sources.list' }
+sub _build_apt_sources_dir { '/etc/apt/sources.list.d' }
sub gather {
my ($self) = @_;
upgradable => transform_exceptions {
return { actions => $self->_gather_upgradable };
},
+ sources => transform_exceptions {
+ return { config => $self->_gather_sources };
+ },
};
}
return handle_from_command 'apt-get -s upgrade';
}
+sub _gather_sources {
+ my ($self) = @_;
+ my $sources_dir = $self->apt_sources_dir;
+ return {
+ 'sources_list' => $self->_fetch_source_list($self->apt_sources),
+ 'sources_list_dir' => (-e $sources_dir) ? transform_exceptions {
+ return +{ files => +{ map {
+ ($_, $self->_fetch_source_list("$sources_dir/$_"));
+ } files_from_dir $sources_dir } };
+ } : {},
+ };
+}
+
+sub _fetch_source_list {
+ my ($self, $file) = @_;
+ return transform_exceptions {
+ return {
+ file => {
+ file_name => $file,
+ body => scalar(output_from_file $file),
+ },
+ };
+ };
+}
+
sub _gather_upgradable {
my ($self) = @_;
my $pipe = $self->_open_apt_get_upgrade_simulation_pipe;
--- /dev/null
+deb http://main.example.com foo
+deb http://main.example.com bar
--- /dev/null
+deb http://other.example.com foo
+deb http://other.example.com bar
do {
local $ENV{PATH} = join ':', "$FindBin::Bin/bin", $ENV{PATH};
+ my $source_list = "$FindBin::Bin/data/apt/sources.list";
+ my $source_list_dir = "$FindBin::Bin/data/apt/sources.list.d";
my $probe = System::Introspector::Probe::Packages::Apt->new(
apt_update => 1,
apt_update_after => 0,
+ apt_sources => $source_list,
+ apt_sources_dir => $source_list_dir,
);
my $data = $probe->gather;
is_deeply $data->{upgradable}, {
}, 'upgradable packages';
ok $data->{update}{last}, 'has last update time';
ok $data->{update}{run}, 'has apt run state';
+ is_deeply $data->{sources}, {
+ config => {
+ sources_list => {
+ file => {
+ file_name => $source_list,
+ body => join "", map "$_\n",
+ "deb http://main.example.com foo",
+ "deb http://main.example.com bar",
+ },
+ },
+ sources_list_dir => {
+ files => {
+ "other.list" => {
+ file => {
+ file_name => "$source_list_dir/other.list",
+ body => join "", map "$_\n",
+ "deb http://other.example.com foo",
+ "deb http://other.example.com bar",
+ },
+ },
+ },
+ }
+ },
+ }, 'sources';
};
done_testing;