diff --git a/lib/Slackware/SlackMan.pm b/lib/Slackware/SlackMan.pm index 0e5d842..a118ad2 100644 --- a/lib/Slackware/SlackMan.pm +++ b/lib/Slackware/SlackMan.pm @@ -21,7 +21,7 @@ BEGIN { @ISA = qw(Exporter); - $VERSION = 'v1.0.3'; + $VERSION = 'v1.0.4'; @EXPORT_OK = ( @Slackware::SlackMan::Utils::EXPORT_OK, diff --git a/lib/Slackware/SlackMan/Command.pm b/lib/Slackware/SlackMan/Command.pm index c0b2a7b..9851c4b 100644 --- a/lib/Slackware/SlackMan/Command.pm +++ b/lib/Slackware/SlackMan/Command.pm @@ -14,7 +14,7 @@ BEGIN { require Exporter; - $VERSION = 'v1.0.3'; + $VERSION = 'v1.0.4'; @ISA = qw(Exporter); @EXPORT_OK = qw(run); %EXPORT_TAGS = ( @@ -75,7 +75,7 @@ sub run { my @lock_commands = qw(update install upgrade remove reinstall clean); - logger->debug(sprintf('Call %s command (cmd: slackman %s)', $command, join(' ', @ARGV))); + logger->debug(sprintf('[CMD] Call "%s" command (cmd: %s, pid: %s)', $command, join( " ", $0, @ARGV ), $$)); # Check running slackman instance and block certain commands (only # informational command are available) @@ -395,17 +395,10 @@ sub _call_update_repo_gpg_key { STDOUT->printflush(" * $repo... "); - my $gpg_key_url = $repo_data->{gpgkey}; my $gpg_key_path = sprintf('%s/%s/GPG-KEY', $slackman_conf->{directory}->{cache}, $repo); - unless (-e $gpg_key_path) { - - make_path(dirname($gpg_key_path)); - - if (download_file($gpg_key_url, $gpg_key_path, "-s")) { - gpg_import_key($gpg_key_path) if (-e $gpg_key_path); - } - + if (download_repository_metadata($repo, 'gpgkey')) { + gpg_import_key($gpg_key_path) if (-e $gpg_key_path); } STDOUT->printflush("done\n"); @@ -1058,19 +1051,23 @@ sub _call_changelog { # Filter disabled repository push(@filters, sprintf('repository NOT IN ("%s")', join('","', get_disabled_repositories()))); - my $sth = $dbh->prepare(sprintf($query, join(' AND ', @filters), $slackman_opts->{'limit'})); + $query = sprintf($query, join(' AND ', @filters), $slackman_opts->{'limit'}); + + my $sth = $dbh->prepare($query); $sth->execute(); - print sprintf("%-60s %-20s %-10s %-20s %s\n", "Package", "Version", "Status", "Timestamp", "Repository"); + print sprintf("%-60s %-20s %-1s %-10s %-20s %s\n", "Package", "Version", " ", "Status", "Timestamp", "Repository"); print sprintf("%s\n", "-"x132); while (my $row = $sth->fetchrow_hashref()) { - print sprintf("%-60s %-20s %-10s %-20s %s\n", - ($row->{'package'} || ''), - ($row->{'version'} || ''), - ($row->{'status'} || ''), - ($row->{'timestamp'} || ''), - ($row->{'repository'} || '') + + print sprintf("%-60s %-20s %-1s %-10s %-20s %s\n", + ($row->{'package'} || ''), + ($row->{'version'} || ''), + ($row->{'security_fix'} ? '!' : ''), + ($row->{'status'} || ''), + ($row->{'timestamp'} || ''), + ($row->{'repository'} || '') ); } @@ -1111,7 +1108,7 @@ sub _call_repo_info { } my $package_nums = $dbh->selectrow_array('SELECT COUNT(*) AS packages FROM packages WHERE repository = ?', undef, $repo_id); - my $last_update = time_to_timestamp(db_meta_get("packages-last-update.$repo_id")); + my $last_update = time_to_timestamp(db_meta_get("last-update.$repo_id.packages")); my @urls = qw/changelog packages manifest checksums gpgkey/; @@ -1120,7 +1117,7 @@ sub _call_repo_info { print sprintf("%-20s %s\n", "ID:", $repo_data->{id}); print sprintf("%-20s %s\n", "Mirror:", $repo_data->{mirror}); print sprintf("%-20s %s\n", "Status:", (($repo_data->{enabled}) ? 'enabled' : 'disabled')); - print sprintf("%-20s %s\n", "Last Update:", $last_update); + print sprintf("%-20s %s\n", "Last Update:", ($last_update || '')); print sprintf("%-20s %s\n", "Priority:", $repo_data->{priority}); print sprintf("%-20s %s\n", "Packages:", $package_nums); diff --git a/lib/Slackware/SlackMan/Config.pm b/lib/Slackware/SlackMan/Config.pm index a9d6afd..5516b93 100644 --- a/lib/Slackware/SlackMan/Config.pm +++ b/lib/Slackware/SlackMan/Config.pm @@ -11,7 +11,7 @@ BEGIN { require Exporter; - $VERSION = 'v1.0.3'; + $VERSION = 'v1.0.4'; @ISA = qw(Exporter); @EXPORT_OK = qw{ diff --git a/lib/Slackware/SlackMan/DB.pm b/lib/Slackware/SlackMan/DB.pm index 90c7c78..d75d56f 100644 --- a/lib/Slackware/SlackMan/DB.pm +++ b/lib/Slackware/SlackMan/DB.pm @@ -11,7 +11,7 @@ BEGIN { require Exporter; - $VERSION = 'v1.0.3'; + $VERSION = 'v1.0.4'; @ISA = qw(Exporter); @EXPORT_OK = qw{ @@ -103,7 +103,9 @@ use constant SLACKMAN_CHANGELOGS_TABLE => qq/CREATE TABLE IF NOT EXISTS "changel "arch" VARCHAR, "build" INTEGER, "tag" VARCHAR, + "category" VARCHAR, "status" VARCHAR, + "description" VARCHAR, "security_fix" BOOL)/; use constant SLACKMAN_METADATA_TABLE => qq/CREATE TABLE IF NOT EXISTS "metadata" ( @@ -156,12 +158,12 @@ sub dbh { sub db_init { foreach (SLACKMAN_TABLES) { - logger->debug(qq/Init table "$_"/); + logger->debug(qq/[DB] Init table "$_"/); $dbh->do(SLACKMAN_SCHEMA->{$_}); } foreach (SLACKMAN_INDEXES) { - logger->debug(qq/Init index "$_"/); + logger->debug(qq/[DB] Init index "$_"/); $dbh->do(SLACKMAN_SCHEMA->{$_}); } @@ -177,7 +179,7 @@ sub db_wipe_tables { } sub db_wipe_table { - logger->debug(qq/Wipe "$_" table/); + logger->debug(qq/[DB] Wipe "$_" table/); $dbh->do("DELETE FROM $_"); } @@ -196,19 +198,19 @@ sub db_insert { } sub db_compact { - logger->debug('Compact database'); + logger->debug('[DB] Compact database'); $dbh->do('PRAGMA VACUUM'); } sub db_reindex { foreach (SLACKMAN_TABLES) { - logger->debug(qq/Reindex "$_" table/); + logger->debug(qq/[DB] Reindex "$_" table/); $dbh->do("REINDEX $_"); } foreach (SLACKMAN_INDEXES) { - logger->debug(qq/Reindex "$_" index/); + logger->debug(qq/[DB] Reindex "$_" index/); $dbh->do("REINDEX $_"); } @@ -216,15 +218,15 @@ sub db_reindex { sub db_bulk_insert { - my ($data) = @_; + my (%params) = @_; - my $table = $data->{'table'}; - my $columns = $data->{'columns'}; - my $values = $data->{'values'}; + my $table = $params{'table'}; + my $columns = $params{'columns'}; + my $values = $params{'values'}; my $n_rows = scalar(@$values); - logger->debug(qq/Insert $n_rows rows into "$table" table/); + logger->debug(qq/[DB] Insert $n_rows rows into "$table" table/); my $query = sprintf("INSERT INTO %s(%s) VALUES(%s)", $table, @@ -236,6 +238,8 @@ sub db_bulk_insert { my $sth = $dbh->prepare($query); + logger->debug(qq/[DB] $query/); + foreach my $row (@$values) { $sth->execute(@$row); } @@ -247,8 +251,7 @@ sub db_bulk_insert { sub db_meta_get { my ($key) = @_; - - logger->debug(qq/Get key "$key" value/); + logger->debug(qq/[DB] Get key "$key" value/); return $dbh->selectrow_array(qq/SELECT value FROM metadata WHERE key = ?/, undef, $key); @@ -257,8 +260,7 @@ sub db_meta_get { sub db_meta_set { my ($key, $value) = @_; - - logger->debug(qq/Set key "$key" value "$value"/); + logger->debug(qq/[DB] Set key "$key" value "$value"/); $dbh->do(qq/DELETE FROM metadata WHERE key = ?/, undef, $key); $dbh->do(qq/INSERT INTO metadata(key, value) VALUES(?, ?)/, undef, $key, $value); @@ -271,7 +273,7 @@ sub db_meta_delete { my ($key) = @_; - logger->debug(qq/Delete key "$key"/); + logger->debug(qq/[DB] Delete key "$key"/); return $dbh->selectrow_array(qq/DELETE FROM metadata WHERE key = ?/, undef, $key); @@ -288,14 +290,14 @@ Slackware::SlackMan::DB - SlackMan DB module use Slackware::SlackMan::DB qw(:all); - db_bulk_insert({ + db_bulk_insert( 'table' => 'foo', 'columns' => [ 'foo', 'bar', 'baz' ], 'values' => [ [1,2,3], [4,5,6] ], - }) + ) =head1 DESCRIPTION diff --git a/lib/Slackware/SlackMan/Logger.pm b/lib/Slackware/SlackMan/Logger.pm index 566a22e..57409d4 100644 --- a/lib/Slackware/SlackMan/Logger.pm +++ b/lib/Slackware/SlackMan/Logger.pm @@ -11,7 +11,7 @@ BEGIN { require Exporter; - $VERSION = 'v1.0.3'; + $VERSION = 'v1.0.4'; @ISA = qw(Exporter); @EXPORT_OK = qw{} diff --git a/lib/Slackware/SlackMan/Package.pm b/lib/Slackware/SlackMan/Package.pm index 605581a..ae50fad 100644 --- a/lib/Slackware/SlackMan/Package.pm +++ b/lib/Slackware/SlackMan/Package.pm @@ -11,7 +11,7 @@ BEGIN { require Exporter; - $VERSION = 'v1.0.3'; + $VERSION = 'v1.0.4'; @ISA = qw(Exporter); @EXPORT_OK = qw{ diff --git a/lib/Slackware/SlackMan/Parser.pm b/lib/Slackware/SlackMan/Parser.pm index 7c24dc8..64277d2 100644 --- a/lib/Slackware/SlackMan/Parser.pm +++ b/lib/Slackware/SlackMan/Parser.pm @@ -14,7 +14,7 @@ BEGIN { require Exporter; - $VERSION = 'v1.0.3'; + $VERSION = 'v1.0.4'; @ISA = qw(Exporter); @EXPORT_OK = qw{ @@ -50,7 +50,7 @@ sub parse_changelog { my $repository = $repo->{'id'}; my $changelog_separator = quotemeta('+--------------------------+'); - unless(download_repository_metadata($repository, 'packages', \&$callback_status)) { + unless(download_repository_metadata($repository, 'changelog', \&$callback_status)) { &$callback_status('skip') if ($callback_status); return(0); } @@ -66,7 +66,7 @@ sub parse_changelog { chomp($changelog_contents); my @changelogs = split(/$changelog_separator/, $changelog_contents); - my @columns = qw(timestamp package status name version arch build tag repository); + my @columns = qw(timestamp package status name version arch build tag repository security_fix category description); my @values = (); &$callback_status('parse') if ($callback_status); @@ -78,92 +78,98 @@ sub parse_changelog { callback_spinner($num); $num++; + chomp($changelog); + my @lines = split(/\n/, trim($changelog)); my $changelog_time = changelog_date_to_time($lines[0]); my $changelog_timestamp = time_to_timestamp($changelog_time); - @lines = @lines[ 1 .. $#lines ]; - - foreach my $line (@lines) { + @lines = @lines[ 1 .. $#lines ]; + $changelog = join("\n", @lines); + $changelog =~ s/(\n^ )/|/gm; - chomp($line); + my @changelog_lines = split(/\n/, $changelog); - next if ($line =~ /^\s/); - next if ($line =~ /\*\:/); - next if ($line =~ /\.img/); + foreach my $line (@changelog_lines) { - next unless ($line =~ /(added|rebuilt|removed|upgraded|patched|updated)/i); + my ($package, $status, $name, $version, $arch, $tag, $build, $description, $security_fix, $text, $category); - my ($package, $status); - my ($name, $version, $arch, $tag, $build); + $security_fix = 0; - # Standard Slackware ChangeLog - if ($line =~ /(([[:graph:]]*)\.(txz|tgz|tbz|tlz)):\s+(Added|Rebuilt|Removed|Upgraded|Updated|Patched)/i) { + # Standard Slackware Changelog format (directory/package.ext: status. description) + if ($line =~ /^([[:graph:]]+):\s+(.*)/gm) { $package = $1; - $status = $4; + $text = $2; - } elsif ($line =~ /([[:graph:]]*):\s+(updated to|upgraded to|added|added a|rebuilt|patched)\s+((v\s|v)([[:graph:]]+))/i) { + ($status, $description) = ($text =~ m/(added|rebuilt|removed|upgraded|updated|patched|renamed|moved|name change|switched).(.*)/gi) if ($text); - $package = $1; - $status = $2; - $version = $3; + $security_fix = 1 if ($description && $description =~ /Security fix/); - $version =~ s/(\.|\;|\,)$//; - $status = 'upgraded' if ($status && $status =~ /(updated|upgraded)/i); - $status = 'added' if ($status && $status =~ /added/i); + $description =~ s/\|/\n/g if ($description); + $description =~ s/^ //gm if ($description); - } elsif ($line =~ /([[:graph:]]*):\s+(updated to|upgraded to|added|added a|rebuilt|patched)\s+([[:graph:]]+)/i) { + my $package_info = package_info(basename($package)); - $package = $1; - $status = $2; - $version = $3; + $name = $package_info->{'name'}; + $version = $package_info->{'version'}; + $arch = $package_info->{'arch'}; + $build = $package_info->{'build'}; + $tag = $package_info->{'tag'}; - $version =~ s/(\.|\;|\,)$//; - $status = 'upgraded' if ($status && $status =~ /(updated|upgraded)/i); - $status = 'added' if ($status && $status =~ /added/i); + } else { - } elsif ($line =~ /([[:graph:]]*) added version (\d.([[:graph:]]*))/i) { + next unless ($line =~ /(added|rebuilt|removed|upgraded|updated|patched|renamed|moved|name change|switched)/i); - $package = $1; - $version = $2; - $status = 'added'; + # AlienBob ChangeLog + if ($line =~ /([[:graph:]]+):\s+(updated to|upgraded to|added|added a|rebuilt|patched)\s+((v\s|v)([[:graph:]]+))/i) { - } elsif ($line =~ /([[:graph:]]*) updated for version (\d.([[:graph:]]*))/i) { + $package = $1; + $status = $2; + $version = $3; - $package = $1; - $version = $2; - $status = 'upgraded'; + # AlienBob Changelog + } elsif ($line =~ /([[:graph:]]+):\s+(updated to|upgraded to|added|added a|rebuilt|patched)\s+([[:graph:]]+)/i) { - # slackonly ChangeLog - } elsif ($line =~ /(([[:graph:]]*)\/([[:graph:]]*))\s(added|removed|rebuilt|updated|upgraded)*/i) { + $package = $1; + $status = $2; + $version = $3; - $package = $1; - $status = $4; + # AlienBob Changelog + } elsif ($line =~ /([[:graph:]]+) added version (\d.([[:graph:]]+))/i) { - } + $package = $1; + $version = $2; + $status = 'added'; - next if (defined($version) && ! $version =~ /\d/); - next unless ($status); + # AlienBob Changelog + } elsif ($line =~ /([[:graph:]]+) updated for version (\d.([[:graph:]]+))/i) { - if ($package =~ /(txz|tgz|tbz|tlz)/) { + $package = $1; + $version = $2; + $status = 'upgraded'; - my $package_info = package_info(basename($package)); + # slackonly ChangeLog + } elsif ($line =~ /(([[:graph:]]+)\/([[:graph:]]+))\s(added|removed|rebuilt|updated|upgraded)*/i) { - next unless ($package_info->{'name'}); - next unless ($package_info->{'version'}); - next unless ($package_info->{'build'} =~ /^[0-9]+$/); + $package = $1; + $status = $4; - $name = $package_info->{'name'}; - $version = $package_info->{'version'}; - $arch = $package_info->{'arch'}; - $build = $package_info->{'build'}; - $tag = $package_info->{'tag'}; + } + + $version =~ s/(\.|\;|\,)$// if ($version); + $package =~ s/\:// if ($package); + + $status = 'upgraded' if ($status && $status =~ /(updated|upgraded)/i); + $status = 'added' if ($status && $status =~ /added/i); - } else { - $name = basename($package); } + next if (defined($version) && $version !~ /\d/); + next unless ($status); + + $category = dirname($package) || ''; + my @row = ( $changelog_timestamp, # timestamp $package, # package @@ -173,22 +179,124 @@ sub parse_changelog { $arch, # arch $build, # build $tag, # tag - $repository # repository + $repository, # repository + $security_fix, # security fix + $category, # category + trim($description), # description ); push(@values, \@row); } + +# foreach my $line (@lines) { +# +# chomp($line); +# +# next if ($line =~ /^\s/); +# next if ($line =~ /\*\:/); +# next if ($line =~ /\.img/); +# +# next unless ($line =~ /(added|rebuilt|removed|upgraded|updated|patched|renamed|moved|name change|switched)/i); +# +# my ($package, $status, $name, $version, $arch, $tag, $build); +# +# # Standard Slackware ChangeLog format (directory/package.ext: status) +# if ($line =~ /([[:graph:]]+t?z):\s+(Added|Rebuilt|Removed|Upgraded|Updated|Patched|Renamed|Moved|Name Change|Switched)/i) { +# +# $package = $1; +# $status = $2; +# +# # AlienBob Changelog +# } elsif ($line =~ /([[:graph:]]+):\s+(updated to|upgraded to|added|added a|rebuilt|patched)\s+((v\s|v)([[:graph:]]+))/i) { +# +# $package = $1; +# $status = $2; +# $version = $3; +# +# # AlienBob Changelog +# } elsif ($line =~ /([[:graph:]]+):\s+(updated to|upgraded to|added|added a|rebuilt|patched)\s+([[:graph:]]+)/i) { +# +# $package = $1; +# $status = $2; +# $version = $3; +# +# # AlienBob Changelog +# } elsif ($line =~ /([[:graph:]]+) added version (\d.([[:graph:]]+))/i) { +# +# $package = $1; +# $version = $2; +# $status = 'added'; +# +# # AlienBob Changelog +# } elsif ($line =~ /([[:graph:]]+) updated for version (\d.([[:graph:]]+))/i) { +# +# $package = $1; +# $version = $2; +# $status = 'upgraded'; +# +# # slackonly ChangeLog +# } elsif ($line =~ /(([[:graph:]]+)\/([[:graph:]]+))\s(added|removed|rebuilt|updated|upgraded)*/i) { +# +# $package = $1; +# $status = $4; +# +# } +# +# next if (defined($version) && ! $version =~ /\d/); +# next unless ($status); +# +# $version =~ s/(\.|\;|\,)$// if ($version); +# $package =~ s/\:// if ($package); +# +# $status = 'upgraded' if ($status && $status =~ /(updated|upgraded)/i); +# $status = 'added' if ($status && $status =~ /added/i); +# +# if ($package =~ /(txz|tgz|tbz|tlz)/) { +# +# my $package_info = package_info(basename($package)); +# +# next unless ($package_info->{'name'}); +# next unless ($package_info->{'version'}); +# next unless ($package_info->{'build'} =~ /^[0-9]+$/); +# +# $name = $package_info->{'name'}; +# $version = $package_info->{'version'}; +# $arch = $package_info->{'arch'}; +# $build = $package_info->{'build'}; +# $tag = $package_info->{'tag'}; +# +# } else { +# $name = basename($package); +# } +# +# my @row = ( +# $changelog_timestamp, # timestamp +# $package, # package +# lc($status), # status +# $name, # name +# $version, # version +# $arch, # arch +# $build, # build +# $tag, # tag +# $repository, # repository +# 0 +# ); +# +# push(@values, \@row); +# +# } + } &$callback_status('save') if ($callback_status); - db_bulk_insert({ + db_bulk_insert( 'table' => 'changelogs', 'columns' => \@columns, 'values' => \@values, - }); + ); db_compact(); @@ -235,6 +343,7 @@ sub parse_packages { my $mirror = $repo->{'mirror'}; my $packages_file = sprintf("%s/%s/PACKAGES.TXT", $slackman_conf->{directory}->{'cache'}, $repository); + return(0) unless (-e $packages_file); my $packages_contents = file_read($packages_file); @@ -298,11 +407,11 @@ sub parse_packages { &$callback_status('save') if ($callback_status); - db_bulk_insert({ + db_bulk_insert( 'table' => 'packages', 'columns' => \@columns, 'values' => \@values, - }); + ); db_compact(); @@ -392,11 +501,11 @@ sub parse_manifest { &$callback_status('save') if ($callback_status); - db_bulk_insert({ + db_bulk_insert( 'table' => 'manifest', 'columns' => \@columns, 'values' => \@values, - }); + ); db_compact(); @@ -504,11 +613,11 @@ sub parse_history { &$callback_status('save') if ($callback_status); - db_bulk_insert({ + db_bulk_insert( 'table' => 'history', 'columns' => \@columns, 'values' => \@values, - }); + ); $dbh->do('PRAGMA VACUUM'); diff --git a/lib/Slackware/SlackMan/Repo.pm b/lib/Slackware/SlackMan/Repo.pm index 43f5f5d..7a83c1d 100644 --- a/lib/Slackware/SlackMan/Repo.pm +++ b/lib/Slackware/SlackMan/Repo.pm @@ -11,7 +11,7 @@ BEGIN { require Exporter; - $VERSION = 'v1.0.3'; + $VERSION = 'v1.0.4'; @ISA = qw(Exporter); @EXPORT_OK = qw{ @@ -32,6 +32,7 @@ BEGIN { use Data::Dumper; use File::Basename; +use File::Path qw(make_path remove_tree); use Slackware::SlackMan::Config qw(:all); use Slackware::SlackMan::Utils qw(:all); @@ -176,48 +177,48 @@ sub get_repositories { sub download_repository_metadata { - my ($repo_id, $meta_id, $callback_status) = @_; + my ($repo_id, $metadata, $callback_status) = @_; - my @metadata = qw(gpgkey packages checksums changelog manifest); + my $metadata_url = $repository->{$repo_id}->{$metadata}; + my $metadata_file = sprintf("%s/%s/%s", $slackman_conf->{directory}->{'cache'}, $repo_id, basename($metadata_url)); - if ($meta_id) { - @metadata = ( $meta_id ); + unless ($metadata_url =~ /^(http(|s)|ftp|file)\:\/\//) { + die(sprintf('Malformed "%s" URI for "%s" repository', $metadata, $repo_id)); } - foreach my $metadata (@metadata) { + logger->debug(sprintf('[REPO/%s] Check "%s" metadata last update', $repo_id, $metadata)); - my $metadata_url = $repository->{$repo_id}->{$metadata}; - my $metadata_file = sprintf("%s/%s/%s", $slackman_conf->{directory}->{'cache'}, $repo_id, basename($metadata_url)); + my $metadata_last_modified = get_last_modified($metadata_url); + my $db_meta_last_modified = db_meta_get("last-update.$repo_id.$metadata"); + $db_meta_last_modified = 0 unless($db_meta_last_modified); - unless ($metadata_url =~ /^(http(|s)|ftp|file)\:\/\//) { - die(sprintf('Malformed URI %s for %s', $metadata, $repo_id)); - } - - logger->debug("Check $metadata last update of $repo_id"); - - my $metadata_last_modified = get_last_modified($metadata_url); - my $db_meta_last_modified = db_meta_get("last-update.$repo_id.$metadata"); - $db_meta_last_modified = 0 unless($db_meta_last_modified); - - # Force update - if ($slackman_opts->{'force'}) { - logger->debug("Force $metadata last update of $repo_id"); - $db_meta_last_modified = 0; - unlink($metadata_file); - } + # Force update + if ($slackman_opts->{'force'}) { + logger->debug(sprintf('[REPO/%s] Force "%s" metadata last update', $repo_id, $metadata)); + $db_meta_last_modified = 0; + unlink($metadata_file); + } - return (0) if ($db_meta_last_modified >= $metadata_last_modified); + logger->debug(sprintf('[REPO/%s] "%s" metadata time (repo: %s - local: %s)', + $repo_id, $metadata, + time_to_timestamp($metadata_last_modified), + time_to_timestamp($db_meta_last_modified))); - unless ( -e $metadata_file) { - &$callback_status('download') if ($callback_status); - download_file($metadata_url, $metadata_file, "-s"); - logger->debug("Download $metadata file for $repo_id"); - } + if ($metadata_last_modified == $db_meta_last_modified) { + logger->debug(sprintf('[REPO/%s] Skip "%s" metadata download', $repo_id, $metadata)); + return (0); + } - db_meta_set("last-update.$repo_id.$metadata", $metadata_last_modified); + make_path(dirname($metadata_file)) unless (-d dirname($metadata_file)); + unless ( -e $metadata_file) { + &$callback_status('download') if ($callback_status); + download_file($metadata_url, $metadata_file, "-s"); + logger->debug(sprintf('[REPO/%s] Download %s metadata file', $repo_id, $metadata)); } + db_meta_set("last-update.$repo_id.$metadata", $metadata_last_modified); + return(1); } diff --git a/lib/Slackware/SlackMan/Utils.pm b/lib/Slackware/SlackMan/Utils.pm index c53320a..35e1da2 100644 --- a/lib/Slackware/SlackMan/Utils.pm +++ b/lib/Slackware/SlackMan/Utils.pm @@ -11,7 +11,7 @@ BEGIN { require Exporter; - $VERSION = 'v1.0.3'; + $VERSION = 'v1.0.4'; @ISA = qw(Exporter); @EXPORT_OK = qw( @@ -164,7 +164,7 @@ sub curl_cmd { my $curl_cmd = "curl $curl_global_flags $curl_flags"; - logger->debug("CURL: $curl_cmd"); + logger->debug("[CURL] $curl_cmd"); return $curl_cmd; @@ -175,7 +175,7 @@ sub file_read_url { my $url = shift; my $curl_cmd = curl_cmd("-s $url"); - logger->info("Downloading $url"); + logger->info("[CURL] Downloading $url"); my $data = qx{ $curl_cmd }; return $data; @@ -190,7 +190,7 @@ sub download_file { my $curl_cmd = curl_cmd("$extra_curl_flags -# -o $output $url"); - logger->info("Downloading $url"); + logger->info("[CURL] Downloading $url"); system($curl_cmd); return ($?) ? 0 : 1; @@ -202,7 +202,7 @@ sub get_last_modified { my $url = shift; my $curl_cmd = curl_cmd("-s -I $url"); - logger->debug(qq/Get "Last-Modified" date of $url/); + logger->debug(qq/[CURL] Get "Last-Modified" date of $url/); my $headers = qx{ $curl_cmd }; my $result = 0; @@ -308,7 +308,7 @@ sub gpg_verify { my $file = shift; - logger->debug(qq/GPG: verify file "$file" width "$file.asc"/); + logger->debug(qq/[GPG] verify file "$file" width "$file.asc"/); system("gpg --verify $file.asc $file 2>/dev/null"); return ($?) ? 0 : 1; @@ -322,7 +322,7 @@ sub gpg_import_key { $key_contents =~ /uid\s+(.*)/; my $key_uid = $1; - logger->debug(qq/GPG: Import key file with "$key_uid" uid/); + logger->debug(qq/[GPG] Import key file with "$key_uid" uid/); system("/usr/bin/gpg --yes --batch --delete-key '$key_uid' &>/dev/null") if ($key_uid); system("/usr/bin/gpg --import $key_file &>/dev/null");