Skip to content

Commit 9476483

Browse files
committed
dshbak: Fix zero padding issue
A user noticed that dshbak was breaking up host lists like 01-11 as 01-09,10-11. This was caused by a bug in the zeropad compatibility test in dshbak. This patch allows 10 to be coalesced with 09 (and 9), 100 with 099, etc. Resolves Issue 33
1 parent 07b4e94 commit 9476483

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
2011-07-26 Mark Grondona <mgrondona@llnl.gov>
22

3+
* scripts/dshbak :
4+
Properly handle coalescing hosts across 9,10 99,100
5+
boundaries when zero-padding is in effect. e.g. 09-10
6+
099-100, etc. (Fixes issue 33).
7+
38
* tests/t5000-dshbak.sh:
49
Add tests for proper compress over zero-pad boundaries
510
like 09-10 and 099-100, etc.

scripts/dshbak

+31-5
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,26 @@ sub compress_inner
261261
}
262262

263263
#
264-
# Return the zeropadding, if any, of $n:
264+
# Return the zeropadded width of $n, where the zero-padded
265+
# width is the minimum format width a number with the given
266+
# zero-padding. That is, no zero-padding is 1, because 0-9
267+
# have a minimum width of 1, "01" has a width of 2, 010 has
268+
# a width of 3 and so on.
265269
#
266-
sub zeropadding
270+
sub zeropadwidth
267271
{
268272
my ($n) = @_;
269-
return (($n =~ /^0/) and ($n ne "0")) ? length $n : 0;
273+
274+
#
275+
# zeropad width is the length of $n if there are any leading
276+
# zeros and the number is not zero itself.
277+
#
278+
return length $n if (($n =~ /^0/) and ($n ne "0"));
279+
280+
#
281+
# If no leading zeros (or $n == 0) then the width is always '1'
282+
#
283+
return 1;
270284
}
271285

272286
sub comp
@@ -281,7 +295,7 @@ sub comp
281295

282296
for my $host (sortn (@_)) {
283297
my ($p, $n) = $host =~ /(.*?)(\d*)$/;
284-
my $zp = &zeropadding ($n);
298+
my $zp = &zeropadwidth ($n);
285299
#
286300
# $s{$p} is a reference to an array of arrays
287301
# that indicate individual range elements of
@@ -292,9 +306,21 @@ sub comp
292306
# with zero-padding $zp into the @{$s{$p}} array.
293307

294308
#
295-
# See if $n-1 exists in the $s{$p} array (with same zero-pad)
309+
# Need to check if $n-1 exists in the $s{$p} array, but the
310+
# zero-padded width must be compatible. e.g.. "9" and "09"
311+
# are compatible with 10, but not with 010.
296312
#
297313
my $idx = $i{$p}{$zp}{$n-1};
314+
315+
#
316+
# If the current zeropad is 1, and the length of $n is > 1,
317+
# then we check for a previous number with either zp == 1 or
318+
# zp == length. This catches 09-10, 099-100, etc .
319+
#
320+
if (!defined $idx && $zp == 1) {
321+
$idx = $i{$p}{length $n}{$n-1};
322+
}
323+
298324
if (defined $idx) {
299325
#
300326
# $n - 1 is already in array, so update END:

0 commit comments

Comments
 (0)