[Bps-public-commit] Module-Install-RTx branch, rtx-remove, created. 0.38-1-g2c392fd

Jim Brandt jbrandt at bestpractical.com
Wed Sep 28 16:57:42 EDT 2016


The branch, rtx-remove has been created
        at  2c392fd9bab45fa7f5c172a8c63607f01092ee4f (commit)

- Log -----------------------------------------------------------------
commit 2c392fd9bab45fa7f5c172a8c63607f01092ee4f
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Sep 28 16:12:46 2016 -0400

    Add option to remove obsolete files on install

diff --git a/README b/README
index a6be4f9..31c813f 100644
--- a/README
+++ b/README
@@ -60,6 +60,27 @@ DESCRIPTION
     error message. This message is passed to sprintf with two string
     arguments, the current RT version and the version you specify.
 
+  remove_obsolete_files
+    If set to a true value, during installation any files listed in a
+    "files_to_remove" file will be removed from the destination directories.
+    This feature is for removing files that have been deleted or moved in
+    the current version and leaving the old version in place when upgrading
+    can cause problems.
+
+    RTx looks for a "files_to_remove" file in the etc/upgrade directory of
+    the distribution. The format of the "files_to_remove" file is as
+    follows:
+
+        package Module::Install::RTx;
+
+        @remove_files = qw(
+        html/dir/file_to_remove
+        );
+        1;
+
+    The file locations are relative to the distribution. The destination
+    directory prefix is added automatically.
+
 CAVEATS
     *   Us the full name when calling RTx method in Makefile.PL; while
         "RTx('Foo')" was once supported, it is no longer.
diff --git a/lib/Module/Install/RTx.pm b/lib/Module/Install/RTx.pm
index 002eb7a..17f3f2f 100644
--- a/lib/Module/Install/RTx.pm
+++ b/lib/Module/Install/RTx.pm
@@ -112,11 +112,28 @@ lexicons ::
 .
     }
 
+    my $remove_files;
+    if( $extra_args->{'remove_obsolete_files'} ){
+        our @remove_files;
+        eval { require "etc/upgrade/files_to_remove" }
+          or print "No remove file located, no files to remove\n";
+        $remove_files = join ",", map {"q(\$(DESTDIR)$plugin_path/$name/$_)"} @remove_files;
+    }
+
     $self->include('Module::Install::RTx::Runtime') if $self->admin;
     $self->include_deps( 'YAML::Tiny', 0 ) if $self->admin;
     my $postamble = << ".";
 install ::
 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Iinc -MModule::Install::RTx::Runtime -e"RTxPlugin()"
+.
+
+    if( $remove_files ){
+        $postamble .= << ".";
+\t\$(NOECHO) \$(PERL) -MModule::Install::RTx::Remove -e \"RTxRemove([$remove_files])\"
+.
+    }
+
+    $postamble .= << ".";
 \t\$(NOECHO) \$(PERL) -MExtUtils::Install -e \"install({$args})\"
 .
 
@@ -348,6 +365,26 @@ Takes an optional second argument which allows you to specify a custom
 error message. This message is passed to sprintf with two string
 arguments, the current RT version and the version you specify.
 
+=head2 remove_obsolete_files
+
+If set to a true value, during installation any files listed in a C<files_to_remove>
+file will be removed from the destination directories. This feature is for
+removing files that have been deleted or moved in the current version and
+leaving the old version in place when upgrading can cause problems.
+
+RTx looks for a C<files_to_remove> file in the etc/upgrade directory of the
+distribution. The format of the C<files_to_remove> file is as follows:
+
+    package Module::Install::RTx;
+
+    @remove_files = qw(
+    html/dir/file_to_remove
+    );
+    1;
+
+The file locations are relative to the distribution. The destination
+directory prefix is added automatically.
+
 =head1 CAVEATS
 
 =over 4
diff --git a/lib/Module/Install/RTx/Remove.pm b/lib/Module/Install/RTx/Remove.pm
new file mode 100644
index 0000000..90c1863
--- /dev/null
+++ b/lib/Module/Install/RTx/Remove.pm
@@ -0,0 +1,39 @@
+package Module::Install::RTx::Remove;
+
+use base 'Exporter';
+our @EXPORT = qw/RTxRemove/;
+
+use strict;
+
+=head1 DESCRIPTION
+
+Remove specified files. Intended to remove files
+from previously installed versions when upgrading
+code in place.
+
+=head1 USAGE
+
+    perl -MModule::Install::RTx::Remove -e "RTxRemove([q(/full/dir/path/file_to_remove)])"
+
+=head1 METHODS
+
+=head2 RTxRemove
+
+Removes specificed files.
+
+Accepts: Arrayref of files to remove. Files should have a full
+directory path.
+
+=cut
+
+sub RTxRemove {
+    my $remove_files = shift;
+
+    # Trying the naive unlink first. If issues are reported,
+    # look at ExtUtils::_unlink_or_rename for more cross-platform options.
+    foreach my $file (@$remove_files){
+        next unless -e $file;
+        print "Removing $file\n";
+        unlink($file) or warn "Could not unlink $file: $!";
+    }
+}

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list