-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.pl
56 lines (44 loc) · 1.91 KB
/
next.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# this works directly on global %PKG
# get_next_sub $release,$archive; inspects release/archive files (relative to tgzdir)
# to get next subversion, by looking into archive or by incrementing saved subversion value
sub get_next_sub {
my $release = "$PKG{tgzdir}/$_[0]";
my $archive = "$PKG{tgzdir}/$_[1]";
# default first member of archive
my $next = "a";
$next = "0" if $PKG{mtype} eq "az";
# reset subversion
if($PKG{subversion} =~ /^reset (.*)$/) {
$PKG{subversion} = $1;
$PKG{next} = "";
$PKM{next} = "<= $1 reset";
return }
# archive does not exist, but we have saved subversion number
if(not -f $archive and defined $PKG{subversion} and $PKG{subversion}) {
my $next = $PKG{subversion};
$PKG{next} = $next;
$PKG{next} ++;
$PKM{next} = "<= $next $PKM{subversion}";
return }
# archive does not exist, but release package does, start subreleases with "a" or "0"
if(not -f $archive and -f $release) {
$PKG{next} = $next;
$PKM{next} = "<= $release";
return }
# nor archive nor release package exist, none next
if(not -f $archive) { return }
# archive exists, get list of subversions from the list of files in archive
my @a;
for(sort split /\n/,`tar tf $archive`) { push @a,$1 if /^[^\/]+\/([^\/]+)\/?$/ }
# print "subs: @a\n";
# find the biggest subbversion in the list
$next = $1 if @a and @a[$#a]=~/$PKG{delimiter}$PKG{version}(.*?)(\.|$)/;
# print " max: $next\n";
# init/change $next to $PKG{subversion} if defined and bigger then in archive
$next = $PKG{subversion} if defined $PKG{subversion} and $PKG{subversion} and $PKG{subversion} gt $next;
# find the first free subversion (but bigger then the current $next)
my sub inarch { my $v=quotemeta $_[1]; for(@{$_[0]}) { return 1 if /$v/ }}
$next++ while inarch \@a,"$PKG{delimiter}$PKG{version}$next";
$PKG{next} = $next;
$PKM{next} = "<- $archive"; }
# R.Jaksa 2001,2023 GPLv3