aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel T. Staal <DStaal@usa.net>2014-05-13 19:59:20 -0400
committerDaniel T. Staal <DStaal@usa.net>2014-05-13 19:59:20 -0400
commit88d8f7428a80e1296ba43226bd49c366623b49ff (patch)
treed79599d487535a3578152b449f1a02f936e2e77e
parentdfcc32ac9f1ebe58f99b4fcf34516897b231bacf (diff)
downloadpandoc-88d8f7428a80e1296ba43226bd49c366623b49ff.tar.gz
Code cleanup and debug.
Various cleanups: - @pkg_info was never used. Removed. - Simplified getting the list of files slightly. - Used list form of system(). This prevents shell interpretation of command and arguments, preventing bugs. (And solves one.) - Changed $! (OS_ERROR) to $? (CHILD_ERROR) after system() calls to get the error from the external program. (Note that $? is the numeric return code from the child program.) - Allow script to continue after finding some of the files have been removed previously. - Convert 'warn "…"; exit 1;' to 'die "…";', the more common equivalent idiom. - Convert 'exit 0;' to 'exit;', to be more clear we are not exiting abnormally. Signed-off-by: Daniel T. Staal <DStaal@usa.net>
-rwxr-xr-xosx/uninstall-pandoc.pl38
1 files changed, 18 insertions, 20 deletions
diff --git a/osx/uninstall-pandoc.pl b/osx/uninstall-pandoc.pl
index 292bcfd96..a5194d9bd 100755
--- a/osx/uninstall-pandoc.pl
+++ b/osx/uninstall-pandoc.pl
@@ -12,8 +12,6 @@ use File::Spec;
# The main info: this is the list of files to remove and the pkg_id.
my $pkg_id = 'net.johnmacfarlane.pandoc';
-my @pkg_info;
-
# Find which, if any, volume Pandoc is installed on.
my $volume;
@@ -39,12 +37,11 @@ if ( $cur_test =~ m/$pkg_id/ ) {
die "Pandoc not installed.\n" if !( defined($volume) );
-my @pkg_files = ();
-my $f;
-for $f (split '\n', `pkgutil --volume '$volume' --only-files --files $pkg_id`) {
- push @pkg_files, File::Spec->rel2abs($f, $volume);
-};
+# Get the list of files to remove.
+my @pkg_files = `pkgutil --volume '$volume' --only-files --files '$pkg_id'`;
+@pkg_files = map { chomp; File::Spec->rel2abs($_, $volume) } @pkg_files;
+# Confirm uninistall with the user.
print "The following files will be deleted:\n\n";
print join("\n", @pkg_files);
print "\n\n";
@@ -54,28 +51,29 @@ my $input = <STDIN>;
if ($input =~ m/^[Yy]/) {
# Actually remove the files.
- foreach $f (@pkg_files) {
- if (system("sudo rm $f") == 0) {
- warn "Deleted $f\n";
- } else {
- warn "Unable to delete $f: $!\n";
- warn "Aborting uninstall.\n";
- exit 1;
+ foreach my $file (@pkg_files) {
+ if ( -e $file ) {
+ if ( system( 'sudo', 'rm', $file ) == 0 ) {
+ warn "Deleted $file\n";
+ } else {
+ warn "Unable to delete $file: $?\n";
+ die "Aborting Uninstall.\n";
+ }
+ } else {
+ warn "File $file does not exist. Skipping.\n";
}
}
# Clean up the install.
- if (system("sudo pkgutil --forget $pkg_id --volume '$volume'") != 0) {
- warn "Unable to clean up install: $!\n";
- exit 1;
+ if (system('sudo', 'pkgutil', '--forget', $pkg_id, '--volume', $volume) != 0) {
+ die "Unable to clean up install: $?\n";
}
} else {
print "OK, aborting uninstall.\n";
- exit 0;
-
+ exit;
}
print "Pandoc has been successfully uninstalled.\n";
-exit 0;
+exit;