@@ -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;