Skip to content

Commit

Permalink
Add parameter strict to /app/package
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-suse committed Nov 26, 2024
1 parent 880c37c commit 67e72ad
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
8 changes: 7 additions & 1 deletion assets/javascripts/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var pkg_param_os_ver;
var pkg_param_repo;
var pkg_param_ign_path;
var pkg_param_ign_file;
var pkg_param_strict;

function initPackageParams() {

Expand All @@ -22,6 +23,7 @@ function initPackageParams() {
pkg_param_repo = urlParams.get('repo');
pkg_param_ign_path = urlParams.get('ignore_path');
pkg_param_ign_file = urlParams.get('ignore_file');
pkg_param_strict = urlParams.get('strict');

if (pkg_param_pkg) {
( document.getElementById("packag") || {} ).value = pkg_param_pkg;
Expand All @@ -47,7 +49,9 @@ function initPackageParams() {
if (pkg_param_ign_file) {
document.getElementById("ign_file").value = pkg_param_ign_file;
}

if (pkg_param_strict) {
( document.getElementById("strict") || {} ).checked = pkg_param_strict? 1 : 0;
}
}

function setupPackages() {
Expand Down Expand Up @@ -151,6 +155,7 @@ function setupPackageLocations(name) {
pkg_param_repo = document.getElementById("repo").value;
pkg_param_ign_path = document.getElementById("ign_path").value;
pkg_param_ign_file = document.getElementById("ign_file").value;
pkg_param_strict = document.getElementById("strict").checked ? 1 : '';

var dataTable = table.DataTable({
ajax: {
Expand All @@ -164,6 +169,7 @@ function setupPackageLocations(name) {
"repo": pkg_param_repo,
"ignore_path": pkg_param_ign_path,
"ignore_file": pkg_param_ign_file,
"strict" : pkg_param_strict,
},
},
deferRender: true,
Expand Down
9 changes: 8 additions & 1 deletion lib/MirrorCache/WebAPI/Controller/Rest/Metapkg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ sub search_locations {
my $p_repo = $self->param('repo');
my $p_ign_path = $self->param('ignore_path');
my $p_ign_file = $self->param('ignore_file');
my $p_strict = $self->param('strict');

my $sql_from = <<'END_SQL';
select metapkg.name, folder.path as path, file.name as file, file.size as size, file.mtime as time
Expand Down Expand Up @@ -71,7 +72,7 @@ END_SQL
my $sql_where = "WHERE file.name like ? and metapkg.name = ?";

push @parms, "$package$arch%";
push @parms, "$package";
push @parms, $package;
if ($p_repo) {
$sql_where = "$sql_where and folder.path like concat('%/', ?::text, '/', ?::text)";
push @parms, $p_repo;
Expand All @@ -85,6 +86,11 @@ END_SQL
$sql_where = "$sql_where and file.name not like concat('%', ?::text, '%')";
push @parms, $p_ign_file;
}
if ($p_strict) {
$sql_where = "$sql_where and file.name ~ ?";
my $qm = quotemeta($package);
push @parms, "^$qm-([^-]+)-([^-]+)\.(x86_64|noarch|i[3-6]86|ppc64|aarch64|arm64|amd64|s390|src)";
}

my $sql = $sql_from . "\n" . $sql_where;

Expand All @@ -107,6 +113,7 @@ sub search {
my $p_repo = $self->param('repo');
my $p_ign_path = $self->param('ignore_path');
my $p_ign_file = $self->param('ignore_file');
my $p_strict = $self->param('strict');

my $sql_from = <<'END_SQL';
select distinct metapkg.name
Expand Down
16 changes: 12 additions & 4 deletions t/environ/24-pkg-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ap7=$(environ ap7)

files=(
/folder1/x86_64/mypkg-1.1-1.1.x86_64.rpm
/folder1/x86_64/mypkg-doc-1.1-1.1.x86_64.rpm
/folder1/x86_64/yourpkg-1.1-1.1.x86_64.rpm
)

Expand All @@ -39,8 +40,8 @@ done
$mc/backstage/job -e folder_sync -a '["/folder1/x86_64"]'
$mc/backstage/shoot

$mc/sql_test 2 == "select count(*) from pkg"
$mc/sql_test 2 == "select count(*) from metapkg"
$mc/sql_test 3 == "select count(*) from pkg"
$mc/sql_test 3 == "select count(*) from metapkg"

$mc/curl /rest/package/mypkg

Expand All @@ -66,13 +67,20 @@ $mc/backstage/job -e folder_sync -a '["/folder1/x86_64"]'
$mc/backstage/job -e folder_sync -a '["/folder2/x86_64"]'
$mc/backstage/shoot

$mc/sql_test 3 == "select count(*) from pkg"
$mc/sql_test 3 == "select count(*) from metapkg"
$mc/sql_test 4 == "select count(*) from pkg"
$mc/sql_test 4 == "select count(*) from metapkg"

$mc/curl /rest/search/packages?package=mypkg

$mc/curl '/rest/search/package_locations?package=mypkg&repo=folder2'

$mc/curl /rest/search/package_locations?package=yourpkg

rc=0
$mc/curl "/rest/search/package_locations?package=mypkg&strict=1" | grep mypkg-doc || rc=$?
test $rc -gt 0

$mc/curl /rest/search/package_locations?package=mypkg | grep mypkg-doc
$mc/curl --globoff '/rest/search/package_locations?package=^([a-zA-Z0-9])(([\-.]|[_]+)?([a-zA-Z0-9]+))*(@){1}[a-z0-9]+[.]{1}(([a-z]{2,3})|([a-z]{2,3}[.]{1}[a-z]{2,3}))$'

echo success
9 changes: 9 additions & 0 deletions templates/app/package/show.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ input[type = text] {
<input id="ign_file" name="ign_file" type="text">
</div>
</div>
<br>
<div class = "col-xl-4">
<div class = col25>
<label class="form-label" for="official">Strict</label>
</div>
<div class = col75>
<input id="strict" name="strict" type="checkbox">
</div>
</div>
</div>
<div class="mb-3">
<input class="btn btn-primary" type="submit" value="Search"/>
Expand Down

0 comments on commit 67e72ad

Please sign in to comment.