[Bps-public-commit] Module-Install-RTx branch, master, updated. 0.38-2-g50e7cb0

Shawn Moore shawn at bestpractical.com
Thu Jan 26 15:51:43 EST 2017


The branch, master has been updated
       via  50e7cb06b39187fe0e736e0b4e9bb45c79d5a090 (commit)
       via  7a8b75afa6727d0ef582912bda9046d18439ce20 (commit)
      from  a2e9dd92443592d7b5c4552b9811b414a226325e (commit)

Summary of changes:
 MANIFEST                         |  1 +
 META.yml                         |  2 ++
 README                           | 20 ++++++++++++++++++++
 lib/Module/Install/RTx.pm        | 40 ++++++++++++++++++++++++++++++++++++++++
 lib/Module/Install/RTx/Remove.pm | 39 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 102 insertions(+)
 create mode 100644 lib/Module/Install/RTx/Remove.pm

- Log -----------------------------------------------------------------
commit 7a8b75afa6727d0ef582912bda9046d18439ce20
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/MANIFEST b/MANIFEST
index 2734a18..3c7c940 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -6,6 +6,7 @@ inc/Module/Install/Metadata.pm
 inc/Module/Install/ReadmeFromPod.pm
 inc/Module/Install/WriteAll.pm
 lib/Module/Install/RTx.pm
+lib/Module/Install/RTx/Remove.pm
 lib/Module/Install/RTx/Runtime.pm
 Makefile.PL
 MANIFEST			This list of files
diff --git a/META.yml b/META.yml
index 4c417b9..e054344 100644
--- a/META.yml
+++ b/META.yml
@@ -22,6 +22,8 @@ provides:
   Module::Install::RTx:
     file: lib/Module/Install/RTx.pm
     version: '0.38'
+  Module::Install::RTx::Remove:
+    file: lib/Module/Install/RTx/Remove.pm
   Module::Install::RTx::Runtime:
     file: lib/Module/Install/RTx/Runtime.pm
 requires:
diff --git a/README b/README
index a6be4f9..3747288 100644
--- a/README
+++ b/README
@@ -60,6 +60,26 @@ DESCRIPTION
     error message. This message is passed to sprintf with two string
     arguments, the current RT version and the version you specify.
 
+  remove_files
+    If set to a true value, during installation any files listed in a
+    "remove_files" 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 "remove_files" file in the etc/upgrade directory of the
+    distribution. The format of the "remove_files" 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..fde44ce 100644
--- a/lib/Module/Install/RTx.pm
+++ b/lib/Module/Install/RTx.pm
@@ -112,11 +112,29 @@ lexicons ::
 .
     }
 
+    my $remove_files;
+    if( $extra_args->{'remove_files'} ){
+        $self->include('Module::Install::RTx::Remove');
+        our @remove_files;
+        eval { require "etc/upgrade/remove_files" }
+          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 +366,28 @@ 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_files
+
+If set to a true value, during installation any files listed in a
+C<remove_files> 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<remove_files> file in the etc/upgrade directory of
+the distribution. The format of the C<remove_files> 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..7e41324
--- /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 specified 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: $!";
+    }
+}

commit 50e7cb06b39187fe0e736e0b4e9bb45c79d5a090
Merge: a2e9dd9 7a8b75a
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Jan 26 20:51:22 2017 +0000

    Merge branch 'rtx-remove'


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


More information about the Bps-public-commit mailing list