/
backup_file.coretag
42 lines (41 loc) · 1.2 KB
/
backup_file.coretag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Copyright 2002-2005 Interchange Development Group (http://www.icdevgroup.org/)
# Licensed under the GNU GPL v2. See file LICENSE for details.
# $Id: backup_file.coretag,v 1.4 2005-11-08 18:14:39 jon Exp $
UserTag backup-file Order file
UserTag backup-file AddAttr
UserTag backup-file Version $Revision: 1.4 $
UserTag backup-file Routine <<EOR
require File::Copy;
require File::Path;
require File::Basename;
sub {
my ($file, $opt) = @_;
my $bu_file = "backup/$file";
$bu_file =~ s://+:/:g ;
$bu_file =~ m:(.*)/: ;
my $bu_dir = $1;
eval {
die ::errmsg("Cannot figure out backup directory from %s", $bu_file)
if ! $bu_dir;
if (! -d $bu_dir) {
File::Path::mkpath($bu_dir)
or die ::errmsg("Cannot make backup directory %s: %s", $bu_dir, $!);
}
if (-f $bu_file) {
my $fn = $bu_file;
$fn =~ s:.*/::;
UI::Primitive::rotate($fn, { Directory => $bu_dir } )
or die ::errmsg("Cannot make backup of %s: %s", $bu_file, $!);
}
#::logDebug("ready to copy $file to $bu_file");
File::Copy::copy($file, $bu_file)
or die ::errmsg("Copy %s to %s: %s", $file, $bu_file, $!);
};
if ($@) {
$::Scratch->{ui_error} = $@;
::logError($::Scratch->{ui_error});
return undef;
}
return 1;
}
EOR