Bug 17600: Standardize our EXPORT_OK
[srvgit] / C4 / Installer / UpgradeBackup.pm
1 package C4::Installer::UpgradeBackup;
2
3 # Copyright (C) 2008 LibLime
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21 use File::Compare qw( compare );
22 use Cwd qw( cwd );
23 use File::Copy;
24 use File::Find qw( find );
25 use File::Spec;
26 use Exporter;
27
28 use vars qw(@ISA @EXPORT );
29
30 @ISA = ('Exporter');
31 @EXPORT = ('backup_changed_files');
32
33 =head1 NAME
34
35 C4::Installer::UpgradeBackup
36
37 =head1 DESCRIPTION
38
39 This is a helper module used during a 'make upgrade' that
40 creates backups of files updated during an upgrade.
41
42 =cut
43
44 sub backup_changed_files {
45     my $from_to = shift;
46     my $suffix = shift;
47     my $verbose = shift;
48     my $inc_uninstall = shift;
49
50     my $cwd = cwd();
51     foreach my $sourceroot (sort keys %$from_to) {
52         my $targetroot = $from_to->{$sourceroot};
53         my $currdir = File::Spec->catdir($cwd, $sourceroot);
54
55         next unless -d $currdir;
56
57         chdir $currdir or die "could not change to $currdir: $!";
58
59         # expand path
60         find(sub {
61             return unless -f $_;
62             my $filename = $_;
63
64             my $targetdir  = File::Spec->catdir($targetroot, $File::Find::dir);
65             my $targetfile = File::Spec->catfile($targetdir, $filename);
66             my $sourcedir  = File::Spec->catdir($currdir, $File::Find::dir);
67             my $sourcefile = File::Spec->catfile($sourcedir, $filename);
68
69             if (-f $targetfile) {
70                 my ($size) = (stat $sourcefile)[7];
71                 my $backup = $targetfile . $suffix;
72                 unless (-s $targetfile == $size and not compare($sourcefile, $targetfile)) {
73                     print "Backed up $targetfile to $backup\n";
74                     File::Copy::copy($targetfile, $backup);
75                 }
76             }
77         }, ".");
78     }
79 }
80
81 =head1 AUTHOR
82
83 Code based on parts of ExtUtils::Install in order to
84 approximately track how it identifies files to
85 install.
86
87 Koha Development Team <http://koha-community.org/>
88
89 Galen Charlton <galen.charlton@liblime.com>
90
91 =cut
92
93 1;