sbotools2

Maintenance fork of the original sbotools version 2
Log | Files | Refs | README

commit 5142975a73ccf3a764596e0ef9ff32c4b06fd2da
parent 45a71cbcb00fca3b41535321450597619289460c
Author: Andreas Guldstrand <andreas.guldstrand@gmail.com>
Date:   Tue, 19 Apr 2016 00:12:22 +0200

SBO::Lib: consolidate error handling in git_sbo_tree()

Diffstat:
MSBO-Lib/lib/SBO/Lib.pm | 19+++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm @@ -319,20 +319,23 @@ sub rsync_sbo_tree { sub git_sbo_tree { script_error('git_sbo_tree requires an argument.') unless @_ == 1; my $url = shift; + my $cwd = getcwd(); + my $res; if (-d "$repo_path/.git" and check_git_remote($repo_path, $url)) { - my $cwd = getcwd(); chdir $repo_path; - system(qw! git fetch !) == 0 or chdir $cwd and return 0; - system(qw! git reset --hard origin !) == 0 or chdir $cwd and return 0; - unlink "$repo_path/SLACKBUILDS.TXT"; - chdir $cwd and return 1; + $res = eval { + die if system(qw! git fetch !) != 0; # if system() doesn't return 0, there was an error + die if system(qw! git reset --hard origin !) != 0; + unlink "$repo_path/SLACKBUILDS.TXT"; + 1; + }; } else { - my $cwd = getcwd(); chdir $config{SBO_HOME}; remove_tree($repo_path) if -d $repo_path; - system(qw/ git clone /, $url, $repo_path) == 0 or chdir $cwd and return 0; - chdir $cwd and return 1; + $res = system(qw/ git clone /, $url, $repo_path) == 0; + return 1 if chdir $cwd and $res; } + return 1 if chdir $cwd and $res; return 0; }