~rgrjr/rgrjr-scripts

748a29d01448981463f6fa0e442035702f173bb8 — Bob Rogers 3 years ago fd23afa
* Backup/Slice.pm:
   + (entry_cmp):  Bug fix:  Sort catalog slices after their dump
     slices, to match "ls" order, so the show-backups.pl --sort=dvd
     option does the right thing.  Also, compare by prefix first, which
     makes more sense (though it doesn't matter to the current code).
* Backup/Dump.pm:
   + (entry_cmp):  Also compare by prefix first.
* test/test-backup-classes.pl:
   + Expect the changed order.
3 files changed, 30 insertions(+), 26 deletions(-)

M Backup/Dump.pm
M Backup/Slice.pm
M test/test-backup-classes.pl
M Backup/Dump.pm => Backup/Dump.pm +14 -11
@@ 19,14 19,16 @@ BEGIN {
}

sub entry_cmp {
    # This sorts first by date backwards, then by level backwards (if someone
    # performs backups at two different levels on the same day, the second is
    # usually an extracurricular L9 dump on top of the other).
    # Compare two dumps, considering the more recent one to be "less than" the
    # other.  This sorts first by prefix forwards, then by date backwards, then
    # by level backwards (if someone performs backups at two different levels
    # on the same day, the second is usually an extracurricular L9 dump on top
    # of the other).
    my ($self, $other) = @_;

    $other->date cmp $self->date
	|| $other->level <=> $self->level
	|| $self->prefix cmp $other->prefix;
    return ($self->prefix cmp $other->prefix
	    || $other->date cmp $self->date
	    || $other->level <=> $self->level);
}

sub file_stem {


@@ 85,12 87,13 @@ indicates the date the dump was made.
=head3 entry_cmp

Given another C<Backup::Dump> instance, return a -1,0,1 comparison value
reflecting the proper sort order of the two instances.
First we compare by C<date> backwards (i.e. putting the most recent
dump first), then by C<level> backwards (if someone
reflecting the proper sort order of the two instances,
considering the more recent one to be "less than" the other.
First we compare by C<prefix> alphabetically forwards, then by
C<date> backwards (i.e. putting the most recent
dump first), and finally by C<level> backwards (if someone
performs backups at two different levels on the same day, the second is
usually an extracurricular L9 dump on top of the other),
and finally by C<prefix> forwards.
usually an extracurricular L9 dump on top of the other).

=head3 file_stem


M Backup/Slice.pm => Backup/Slice.pm +14 -13
@@ 87,18 87,17 @@ sub listing {
}

sub entry_cmp {
    # This sorts first by date backwards, then by level backwards (if someone
    # performs backups at two different levels on the same day, the second is
    # usually an extracurricular L9 dump on top of the other), then prefix
    # alphabetically, then by catalog_p (to put the catalogs first), and
    # finally by index (for when a single backup is split across multiple
    # files).
    # This sorts first prefix forwards, then by date backwards, then by level
    # backwards (if someone performs backups at two different levels on the
    # same day, the second is usually an extracurricular L9 dump on top of the
    # other), then by catalog_p (to put the catalogs last as "ls" does), and
    # finally by slice index.
    my ($self, $other) = @_;

    $other->date cmp $self->date
    $self->prefix cmp $other->prefix
	|| $other->date cmp $self->date
	|| $other->level <=> $self->level
	|| $self->prefix cmp $other->prefix
	|| ($other->catalog_p || 0) <=> ($self->catalog_p || 0)
	|| ($self->catalog_p || 0) <=> ($other->catalog_p || 0)
	|| $self->index <=> $other->index;
}



@@ 135,12 134,14 @@ indicates the date the dump was made.

Given another C<Backup::Slice> instance, return a -1,0,1 comparison
value reflecting the proper sort order of the two instances.  First we
compare by C<date> backwards (i.e. putting the most recent dump
compare by C<prefix> alphabetically forwards, then by C<date>
backwards (i.e. putting the most recent dump with a given prefix
first), then by C<level> backwards (if someone performs backups at two
different levels on the same day, the second is usually an
extracurricular L9 dump on top of the other), then by by C<prefix>
alphabetically forwards, then by catalog_p (to put the catalogs
first), and finally by ascending index (for when a single backup is
extracurricular L9 dump on top of the other), then by L</catalog_p>
(to put the catalogs last, which matches C<ls> order for the sake of
the C<--show-backups.pl> C<--sort=dvd> option), and finally by
ascending slice index (for when a single dump is
split across multiple files).  Since one usually only sorts slices
from the same C<Backup::Dump>, only the last two comparisons are
likely to be significant.

M test/test-backup-classes.pl => test/test-backup-classes.pl +2 -2
@@ 99,8 99,8 @@ for my $i (0..$n_dumps-1) {
	for my $k ($j..$n_slices-1) {
	    my $slice_k = $slices->[$k];
	    my $result = ($slice_j->catalog_p
			  ? ($slice_k->catalog_p ? $j <=> $k : -1)
			  : ($slice_k->catalog_p ? 1 : $j <=> $k));
			  ? ($slice_k->catalog_p ? $j <=> $k : 1)
			  : ($slice_k->catalog_p ? -1 : $j <=> $k));
	    test_slice_order($slice_j, $slice_k, $result);
	}
    }