Skip to content

Commit

Permalink
Use a set of constant enums for when mldistwatch decides to ignore a …
Browse files Browse the repository at this point in the history
…dist.

- The actual values are the same, where possible.  Some values were just '1'
  which has been made more specific.
- These are only used in one place.
- Now we can easily route the log lines for metadata and readme files to the
  debug log
  • Loading branch information
rspier committed May 4, 2024
1 parent 3992a1a commit af643d5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
8 changes: 4 additions & 4 deletions lib/PAUSE/dist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ sub ignoredist {
my $self = shift;
my $dist = $self->{DIST};
if ($dist =~ m|/\.|) {
$Logger->log("Warning: illegal filename");
return 1;
return PAUSE::mldistwatch::Constants::IGFILENAME;
}

return 1 if $dist =~ /(\.readme|\.sig|\.meta|CHECKSUMS)$/;
return PAUSE::mldistwatch::Constants::IGMETADATA
if $dist =~ /(\.readme|\.sig|\.meta|CHECKSUMS)$/;

# Stupid to have code that needs to be maintained in two places,
# here and in edit.pm:
return "weird CNANDOR case"
return PAUSE::mldistwatch::Constants::IGCNANDOR
if $dist =~ m!CNANDOR/(?:mp_(?:app|debug|doc|lib|source|tool)|VISEICat(?:\.idx)?|VISEData)!;

return;
Expand Down
22 changes: 10 additions & 12 deletions lib/PAUSE/mldistwatch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ our $MAINTAIN_SYMLINKTREE = 1;
use Fcntl qw(:flock);
# this class shows that it was born as spaghetticode

# This can/should be replaced by making things like "reasons to skip indexing a
# dist" into an enumerated type. Until that happens, though, this one needs to
# be easy to refer to, because it's compared against (search for the var name
# below). -- rjbs, 2024-04-28
my $OLD_UNCHANGED_FILE = "file mtime has not changed";

sub new {
my $class = shift;
my $opt = shift;
Expand Down Expand Up @@ -411,15 +405,15 @@ sub reason_to_skip_dist {

unless (exists $self->{ALLfound}{$dist}) {
$dio->delete_goner;
return "it's a goner";
return PAUSE::mldistwatch::Constants::IGGONER;
}

unless ($dio->mtime_ok($self->{ALLlasttime}{$dist})){
return $OLD_UNCHANGED_FILE;
return PAUSE::mldistwatch::Constants::IGUNCHANGED;
}

unless ($dio->lock) {
return "could not obtain a lock";
return PAUSE::mldistwatch::Constants::IGNOLOCK;
}

return;
Expand All @@ -436,9 +430,13 @@ sub maybe_index_dist {
local $Logger = $Logger->proxy({ proxy_prefix => "$dist: " });

if (my $skip_reason = $self->reason_to_skip_dist($dio)) {
# We don't log on $OLD_UNCHANGED_FILE because it's extremely common and
# leads to noise in the logs. -- rjbs, 2024-04-28
my $log_method = $skip_reason eq $OLD_UNCHANGED_FILE ? 'log_debug' : 'log';
# We don't log on IGUNCHANGED and IGMETADATA because
# they're extremely common and lead
my $log_method = "log";
if ($skip_reason eq PAUSE::mldistwatch::Constants::IGUNCHANGED
or $skip_reason eq PAUSE::mldistwatch::Constants::IGMETADATA) {
$log_method = 'log_debug';
}
$Logger->$log_method("skipping: $skip_reason");

delete $self->{ALLlasttime}{$dist};
Expand Down
8 changes: 8 additions & 0 deletions lib/PAUSE/mldistwatch/Constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ sub heading ($) {
$heading->{$status};
}

# constants used for ignoredist
use constant IGFILENAME => 'illegal filename';
use constant IGMETADATA => 'metadata';
use constant IGCNANDOR => 'weird CNANDOR case';
use constant IGGONER => "it's a goner";
use constant IGNOLOCK => 'could not obtain a lock';
use constant IGUNCHANGED => 'file mtime has not changed';

1;


0 comments on commit af643d5

Please sign in to comment.