git.iko.soy/typeable/pandoc
on master help sign in
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>

commit88d8f7428a80e1296ba43226bd49c366623b49ff authorDaniel T. Staal <DStaal@usa.net> dateTue 13 May 2014, 19:59 (12 years ago) parentdfcc32a
1 file changed+18−20
osx/uninstall-pandoc.pl+18−20
osx/uninstall-pandoc.pl+18−20
@@ -12,8 +12,6 @@ use File::Spec;
1212# The main info: this is the list of files to remove and the pkg_id.
1313my $pkg_id = 'net.johnmacfarlane.pandoc';
1414
15−my @pkg_info;
16−
1715# Find which, if any, volume Pandoc is installed on.
1816my $volume;
1917
@@ -39,12 +37,11 @@ if ( $cur_test =~ m/$pkg_id/ ) {
3937
4038die "Pandoc not installed.\n" if !( defined($volume) );
4139
42−my @pkg_files = ();
43−my $f;
44−for $f (split '\n', `pkgutil --volume '$volume' --only-files --files $pkg_id`) {
45− push @pkg_files, File::Spec->rel2abs($f, $volume);
46−};
40+# Get the list of files to remove.
41+my @pkg_files = `pkgutil --volume '$volume' --only-files --files '$pkg_id'`;
42+@pkg_files = map { chomp; File::Spec->rel2abs($_, $volume) } @pkg_files;
4743
44+# Confirm uninistall with the user.
4845print "The following files will be deleted:\n\n";
4946print join("\n", @pkg_files);
5047print "\n\n";
@@ -54,28 +51,29 @@ my $input = <STDIN>;
5451if ($input =~ m/^[Yy]/) {
5552
5653 # Actually remove the files.
57− foreach $f (@pkg_files) {
58− if (system("sudo rm $f") == 0) {
59− warn "Deleted $f\n";
60− } else {
61− warn "Unable to delete $f: $!\n";
62− warn "Aborting uninstall.\n";
63− exit 1;
54+ foreach my $file (@pkg_files) {
55+ if ( -e $file ) {
56+ if ( system( 'sudo', 'rm', $file ) == 0 ) {
57+ warn "Deleted $file\n";
58+ } else {
59+ warn "Unable to delete $file: $?\n";
60+ die "Aborting Uninstall.\n";
61+ }
62+ } else {
63+ warn "File $file does not exist. Skipping.\n";
6464 }
6565 }
6666
6767 # Clean up the install.
68− if (system("sudo pkgutil --forget $pkg_id --volume '$volume'") != 0) {
69− warn "Unable to clean up install: $!\n";
70− exit 1;
68+ if (system('sudo', 'pkgutil', '--forget', $pkg_id, '--volume', $volume) != 0) {
69+ die "Unable to clean up install: $?\n";
7170 }
7271
7372} else {
7473
7574 print "OK, aborting uninstall.\n";
76− exit 0;
77−
75+ exit;
7876}
7977
8078print "Pandoc has been successfully uninstalled.\n";
81−exit 0;
79+exit;