Blame 0001-Fix-URLs-for-needles-in-subdirectories-POO-58959.patch

ff962cb
From 96188d8067a365b2f4a4ffbdb327b2ec8214c19c Mon Sep 17 00:00:00 2001
ff962cb
From: Adam Williamson <awilliam@redhat.com>
ff962cb
Date: Fri, 1 Nov 2019 12:03:35 -0700
ff962cb
Subject: [PATCH] Fix URLs for needles in subdirectories (POO #58959)
ff962cb
ff962cb
As discussed in the POO, this was broken by PR #2410 commit
ff962cb
36aa974 - it assumes you can always find a needle simply by
ff962cb
sticking the needle filename on the end of a `needledir` call,
ff962cb
but you can't, needles are allowed to be in subdirectories of
ff962cb
needledir. This should hopefully fix that without breaking
ff962cb
the custom run case by using the *whole* of the JSON file path -
ff962cb
we just figure out the subdirectory component from it. This works
ff962cb
for me in the 'needle is in a subdirectory of the normal needle
ff962cb
dir' case, but I didn't test it in the custom run case.
ff962cb
ff962cb
Signed-off-by: Adam Williamson <awilliam@redhat.com>
ff962cb
---
ff962cb
 lib/OpenQA/WebAPI/Controller/File.pm | 20 +++++++++++++++++++-
ff962cb
 1 file changed, 19 insertions(+), 1 deletion(-)
ff962cb
ff962cb
diff --git a/lib/OpenQA/WebAPI/Controller/File.pm b/lib/OpenQA/WebAPI/Controller/File.pm
ff962cb
index ad1b004f..ed73f9be 100644
ff962cb
--- a/lib/OpenQA/WebAPI/Controller/File.pm
ff962cb
+++ b/lib/OpenQA/WebAPI/Controller/File.pm
ff962cb
@@ -43,7 +43,25 @@ sub needle {
ff962cb
     }
ff962cb
 
ff962cb
     # locate the needle in the needle directory for the given distri and version
ff962cb
-    push(@{($self->{static} = Mojolicious::Static->new)->paths}, needledir($distri, $version));
ff962cb
+    my $needledir = needledir($distri, $version);
ff962cb
+    # we need to handle the needle being in a subdirectory - we cannot
ff962cb
+    # assume it is always just '$needledir/$name.$format'. figure out
ff962cb
+    # subdirectory elements from the JSON file path
ff962cb
+    my ($dummy1, $path, $dummy2) = fileparse($jsonfile);
ff962cb
+    # drop the trailing / from $path
ff962cb
+    $path = substr($path, 0, -1);
ff962cb
+    if (index($path, '/needles') != -1) {
ff962cb
+        # we got something like /var/lib/openqa/share/tests/distri/needles/(subdir)/needle.json
ff962cb
+        my @elems = split('/needles', $path, 2);
ff962cb
+        if (defined $elems[1]) {
ff962cb
+            $needledir .= $elems[1];
ff962cb
+        }
ff962cb
+    }
ff962cb
+    elsif ($path ne '.') {
ff962cb
+        # we got something like subdir/needle.json, $path will be "subdir"
ff962cb
+        $needledir .= "/$path";
ff962cb
+    }
ff962cb
+    push(@{($self->{static} = Mojolicious::Static->new)->paths}, $needledir);
ff962cb
 
ff962cb
     # name is an URL parameter and can't contain slashes, so it should be safe
ff962cb
     return $self->serve_static_($name . $format);
ff962cb
-- 
ff962cb
2.24.0.rc1
ff962cb