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