diff options
author | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-04-19 00:12:22 +0200 |
---|---|---|
committer | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2016-04-19 00:12:22 +0200 |
commit | 5142975a73ccf3a764596e0ef9ff32c4b06fd2da (patch) | |
tree | 4f2b775dc7083b8e1b2f5d9ba578af599bfa0a57 | |
parent | 45a71cbcb00fca3b41535321450597619289460c (diff) | |
download | sbotools2-5142975a73ccf3a764596e0ef9ff32c4b06fd2da.tar.xz |
SBO::Lib: consolidate error handling in git_sbo_tree()
-rw-r--r-- | SBO-Lib/lib/SBO/Lib.pm | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm index e112f89..0a4508c 100644 --- 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; } |