Skip to content
Snippets Groups Projects
Commit c27bfa89 authored by Alad Wenter's avatar Alad Wenter
Browse files

repo-parse: guard against empty attributes

parent 263d804d
No related branches found
No related tags found
No related merge requests found
......@@ -36,28 +36,15 @@ my %repo_add_attributes = (
'ISIZE' => ['numeric', 'ISize' ]
);
sub check_attr {
my ($attr) = @_;
return $repo_add_attributes{$attr}->[1];
}
sub check_type {
my ($attr) = @_;
return $repo_add_attributes{$attr}->[0];
}
sub check_option {
my ($opt, $opt_label, $attr_def) = @_;
my ($opt, $opt_label) = @_;
my $attr = $repo_add_attributes{uc($opt)};
if (length $opt) {
my $attr = check_attr(uc($opt));
if (not defined $attr) {
say STDERR "$argv0: $opt_label: unknown attribute '$opt'";
exit(2);
}
return $attr;
} else {
return $attr_def;
if (not defined $attr) {
say STDERR "$argv0: $opt_label: unknown attribute '$opt'";
exit(2);
}
return $attr->[1];
}
sub parse_db {
......@@ -259,7 +246,7 @@ unless (caller) {
my $opt_table = 0;
my $opt_quiet = 0;
my $opt_delim;
my $opt_attr = "";
my $opt_attr;
my @opt_db_path;
my $opt_stdin = 0;
my $opt_search = "" ;
......@@ -306,13 +293,9 @@ unless (caller) {
$callback = \&repo_jsonl;
# @varargs defined in input loop
}
elsif (length($opt_attr)) {
my $attr_label = check_attr($opt_attr);
elsif (defined $opt_attr) {
my $attr_label = check_option($opt_attr, '--attr');
if (not defined $attr_label) {
say STDERR "$argv0: unknown attribute '$opt_attr'";
exit(2);
}
$callback = \&repo_attr;
@varargs = ($attr_label);
}
......@@ -331,12 +314,12 @@ unless (caller) {
# Verify search field
my $search = length($opt_search) ? $opt_search : "";
my $search_by = check_option($opt_search_by, '--search-by', 'Name');
my $search_by = defined($opt_search_by) ? check_option($opt_search_by, '--search-by') : 'Name';
# Verify ignores field
my %ignore;
$ignore{$_}++ for (map { split(',', $_) } @opt_ignore);
my $ignore_by = check_option($opt_ignore_by, '--ignore-by', 'Name');
my $ignore_by = defined($opt_ignore_by) ? check_option($opt_ignore_by, '--ignore-by') : 'Name';
# Chain callbacks
my $handler = sub {
......
......@@ -8,8 +8,8 @@ diff -u <(pacsift --repo=core | expac -S '%n\t%v' - | sort -u) \
<(aur repo-parse -p "$core_path" --list | sort -u)
# check attributes are up-to-date
cnt1=$({ echo GROUPS; bsdtar -Oxf "$core_files_path" | grep -Po '(?<=%).+(?=%)'; } | sort -u | wc -l) \
cnt2=$(aur repo-parse --list-attr | wc -l)
cnt1=$({ echo GROUPS; bsdtar -Oxf "$core_files_path" | grep -Po '(?<=%).+(?=%)'; } | sort -u | wc -l)
cnt2=$(aur repo-parse --list-attr | wc -l)
(( cnt1 == cnt2 ))
# check if output is valid JSON
......@@ -49,3 +49,18 @@ json_cnt4=$(aur repo-parse -p "$core_files_path" --search 'aaaaaaaa' --json)
# --json output with constrained entries
aur repo-parse -p "$core_files_path" --json -s '^a' | jq '. | length' >/dev/null
# --attr arguments
aur repo-parse -p "$core_files_path" --attr '' || err=$?
[[ $err == 2 ]]
aur repo-parse -p "$core_files_path" --attr 'notafield' || err=$?
[[ $err == 2 ]]
list_cnt1=$(aur repo-parse -p "$core_files_path" --attr Name | wc -l)
list_cnt2=$(aur repo-parse -p "$core_files_path" --list | wc -l)
(( list_cnt1 == list_cnt2 ))
# --search arguments
aur repo-parse -p "$core_files_path" --list --search --search-by '' || err=$?
[[ $err == 2 ]]
aur repo-parse -p "$core_files_path" --list --search --search-by 'notafield' || err=$?
[[ $err == 2 ]]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment