@@ -12,8 +12,6 @@ use File::Spec;
12# The main info: this is the list of files to remove and the pkg_id.
12# The main info: this is the list of files to remove and the pkg_id.
13my $pkg_id = 'net.johnmacfarlane.pandoc';
13my $pkg_id = 'net.johnmacfarlane.pandoc';
17# Find which, if any, volume Pandoc is installed on.
15# Find which, if any, volume Pandoc is installed on.
18my $volume;
16my $volume;
@@ -39,12 +37,11 @@ if ( $cur_test =~ m/$pkg_id/ ) {
40die "Pandoc not installed.\n" if !( defined($volume) );
38die "Pandoc not installed.\n" if !( defined($volume) );
42−my @pkg_files = ();
40+# Get the list of files to remove.
44−for $f (split '\n', `pkgutil --volume '$volume' --only-files --files $pkg_id`) {
41+my @pkg_files = `pkgutil --volume '$volume' --only-files --files '$pkg_id'`;
45− push @pkg_files, File::Spec->rel2abs($f, $volume);
42+@pkg_files = map { chomp; File::Spec->rel2abs($_, $volume) } @pkg_files;
44+# Confirm uninistall with the user.
48print "The following files will be deleted:\n\n";
45print "The following files will be deleted:\n\n";
49print join("\n", @pkg_files);
46print join("\n", @pkg_files);
50print "\n\n";
47print "\n\n";
@@ -54,28 +51,29 @@ my $input = <STDIN>;
54if ($input =~ m/^[Yy]/) {
51if ($input =~ m/^[Yy]/) {
56 # Actually remove the files.
53 # Actually remove the files.
57− foreach $f (@pkg_files) {
54+ foreach my $file (@pkg_files) {
58− if (system("sudo rm $f") == 0) {
56+ if ( system( 'sudo', 'rm', $file ) == 0 ) {
59− warn "Deleted $f\n";
57+ warn "Deleted $file\n";
61− warn "Unable to delete $f: $!\n";
59+ warn "Unable to delete $file: $?\n";
62− warn "Aborting uninstall.\n";
60+ die "Aborting Uninstall.\n";
63+ warn "File $file does not exist. Skipping.\n";
67 # Clean up the install.
67 # Clean up the install.
68− if (system("sudo pkgutil --forget $pkg_id --volume '$volume'") != 0) {
68+ if (system('sudo', 'pkgutil', '--forget', $pkg_id, '--volume', $volume) != 0) {
69− warn "Unable to clean up install: $!\n";
69+ die "Unable to clean up install: $?\n";
75 print "OK, aborting uninstall.\n";
74 print "OK, aborting uninstall.\n";
80print "Pandoc has been successfully uninstalled.\n";
78print "Pandoc has been successfully uninstalled.\n";