aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Guldstrand <andreas.guldstrand@gmail.com>2015-12-12 17:45:39 +0100
committerAndreas Guldstrand <andreas.guldstrand@gmail.com>2015-12-12 17:45:39 +0100
commitd6b83f8450f6632e353e8389f2aae1ce9524ba32 (patch)
treea9c34b5e8d21ebaea21e709741965cfe2c2f4ca3
parent839e6ef83c3c39e7a525ca713d5feecb5b85ea2e (diff)
downloadsbotools2-d6b83f8450f6632e353e8389f2aae1ce9524ba32.tar.xz
SBO::Lib: Fix in(), and use it in more places
-rw-r--r--SBO-Lib/lib/SBO/Lib.pm17
-rwxr-xr-xsboclean4
2 files changed, 12 insertions, 9 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm
index fb15ac7..dade391 100644
--- a/SBO-Lib/lib/SBO/Lib.pm
+++ b/SBO-Lib/lib/SBO/Lib.pm
@@ -55,6 +55,7 @@ our @EXPORT_OK = qw(
usage_error
uniq
is_local
+ in
$tempdir
$conf_dir
$conf_file
@@ -222,8 +223,11 @@ sub chk_slackbuilds_txt {
# Checks if the first argument equals any of the subsequent ones
sub in {
- my ($first, @rest) @_;
- foreach my $arg (@rest) { return 1 if $first eq $arg; }
+ my ($first, @rest) = @_;
+ foreach my $arg (@rest) {
+ return 1 if ref $arg eq 'Regexp' and $first =~ $arg;
+ return 1 if $first eq $arg;
+ }
return 0;
}
@@ -243,7 +247,7 @@ sub check_repo {
if (-d $repo_path) {
opendir(my $repo_handle, $repo_path);
FIRST: while (my $dir = readdir $repo_handle) {
- next FIRST if $dir =~ /^\.[\.]{0,1}$/;
+ next FIRST if in($dir => qw/ . .. /);
usage_error("$repo_path exists and is not empty. Exiting.\n");
}
} else {
@@ -339,7 +343,7 @@ sub generate_slackbuilds_txt {
for my $cat (@categories) {
opendir(my $cat_dh, "$repo_path/$cat") or return 0;
while (my $package = readdir($cat_dh)) {
- next if $package =~ /^\.\.?$/;
+ next if in($package => qw/ . .. /);
next unless -f "$repo_path/$cat/$package/$package.info";
print { $fh } "SLACKBUILD NAME: $package\n";
print { $fh } "SLACKBUILD LOCATION: ./$cat/$package\n";
@@ -875,8 +879,7 @@ sub get_src_dir {
# scripts use either $TMP or /tmp/SBo
if (opendir(my $tsbo_dh, $tmpd)) {
FIRST: while (my $ls = readdir $tsbo_dh) {
- next FIRST if $ls =~ /^\.[\.]{0,1}$/;
- next FIRST if $ls =~ /^package-/;
+ next FIRST if in($ls => qw/ . .. /, qr/^package-/);
next FIRST unless -d "$tmpd/$ls";
my $found = 0;
seek $fh, 0, 0;
@@ -942,7 +945,7 @@ sub perform_sbo {
my $src_ls_fh = tempfile(DIR => $tempdir);
if (opendir(my $tsbo_dh, $tmpd)) {
FIRST: while (my $dir = readdir $tsbo_dh) {
- next FIRST if $dir =~ /^\.[\.]{0,1}$/;
+ next FIRST if in($dir => qw/ . .. /);
say {$src_ls_fh} $dir;
}
}
diff --git a/sboclean b/sboclean
index 36f86e6..3f0e495 100755
--- a/sboclean
+++ b/sboclean
@@ -13,7 +13,7 @@
use 5.16.0;
use strict;
use warnings FATAL => 'all';
-use SBO::Lib qw/ usage_error script_error /;
+use SBO::Lib qw/ usage_error script_error in /;
use File::Basename;
use Getopt::Long qw(:config bundling);
use File::Path qw(remove_tree);
@@ -73,7 +73,7 @@ sub remove_stuff {
my $dir = shift;
opendir(my $dh, $dir);
FIRST: while (my $ls = readdir $dh) {
- next FIRST if $ls =~ /^(\.){1,2}$/;
+ next FIRST if in($ls => qw/ . .. /);
rm_full("$dir/$ls");
}
}