Skip to content

Commit

Permalink
Improve detection of X-MEDIA-VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-suse committed Dec 18, 2024
1 parent 1bb100f commit 45e0cb9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/Directory/Scanner/OBSMediaVersion.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@ sub parse_version($filename) {
$f = $f->basename;

if ($filename =~ /.*(Build|Snapshot)((\d)+(\.\d+)?).*/) {
return $2
return $2;
}

if ($filename =~ /.*-(\d+\.?\d*\.?\d*\.?\d*)-(\d*\.?\d*)?.*(\.d?rpm)?$/) {
if ($filename =~ /.*-(\d+\.?\d*\.?\d*\.?\d*)-(\d*\.?\d*)?.*(\.d?rpm)$/) {
return $1;
}

return undef unless $filename =~ /.*_(\d+\.?\d*\.?\d*\.?\d*)-(\d*\.?\d*)?.*(\.deb)?$/;
if ($filename =~ m/(.*)_([^-]+)-([^-]+)\.(x86_64|noarch|i[3-6]86|ppc64|aarch64|arm64|amd64|s390|src).*\.drpm$/) {
return $2;
}

my $fil = Mojo::File->new($filename);
my $ext = $fil->extname;
my $basename = $fil->basename(".$ext");

if ($basename =~ m/(.*)(_|-)([^-]+)\.(x86_64|noarch|i[3-6]86|ppc64|aarch64|arm64|amd64|s390|src)$/) {
return $3;
}

return undef unless $filename =~ /.*_(\d+\.?\d*\.?\d*\.?\d*)-(\d*\.?\d*)?.*(\.deb)$/;
return $1
}

Expand All @@ -28,18 +40,18 @@ sub parse_pkg($filename) {
my $f = $fil->basename;
my $ext = $fil->extname;
if ($ext eq "rpm") {
my @res = parse_pkg_rpm( $fil->basename($ext) );
my @res = parse_pkg_rpm( $fil->basename(".$ext") );
return ( @res, "rpm" );
} elsif ($ext eq "deb") {
my @res = parse_pkg_deb( $fil->basename($ext) );
my @res = parse_pkg_deb( $fil->basename(".$ext") );
return ( @res, "deb" );
}
return undef;
}

# return name, version, build, arch
sub parse_pkg_rpm($basename) {
return undef unless ($basename =~ m/(.*)-([^-]+)-([^-]+)\.(x86_64|noarch|i[3-6]86|ppc64|aarch64|arm64|amd64|s390|src)/);
return undef unless ($basename =~ m/(.*)-([^-]+)-([^-]+)\.(x86_64|noarch|i[3-6]86|ppc64|aarch64|arm64|amd64|s390|src)$/);
return ($1, $2, $3, $4);
}

Expand Down
10 changes: 10 additions & 0 deletions t/environ/02-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ for x in $mc $ap7 $ap8; do
echo $x/dt/folder1/file1.dat | xargs -n 1 touch
echo $x/dt/Folder1/file1.1.DAT | xargs -n 1 touch
echo $x/dt/Folder1/repodata/repomd.xml | xargs -n 1 touch
( cd $x/dt/folder1/ ; touch GNOME_3.6.2.x86_64.iso ; ln -s GNOME_3.6.2.x86_64.iso GNOME_Next.x86_64.iso )
mkdir -p $x/dt/folder1.11test/
for f in $unversionedfiles; do
str=1
Expand Down Expand Up @@ -207,5 +208,14 @@ $mc/curl -i -H "Accept: */*, application/metalink+xml" /download/Folder1/repodat
$mc/curl -i /download/folder1/file1.1.dat | grep Cache-Control
$mc/curl -i /download/Folder1/file1.1.DAT | grep Cache-Control

echo check x-media-version
$mc/curl -i /download/folder1/GNOME_3.6.2.x86_64.iso | grep 'X-MEDIA-VERSION: 3.6.2'

$mc/curl -i /download/folder1/GNOME_Next.x86_64.iso | grep 'X-MEDIA-VERSION: 3.6.2'

echo check dont detect x-media-version in openSUSE-Leap-15.3-NET-x86_64.iso
rc=0
$mc/curl -i /download/folder1.11test/openSUSE-Leap-15.3-NET-x86_64.iso | grep 'X-MEDIA-VERSION:' || rc=$?
test $rc -gt 0

echo success

0 comments on commit 45e0cb9

Please sign in to comment.