summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2020-01-20 07:16:55 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2020-01-20 07:28:52 (GMT)
commite975c3fd84c4b23b653b286739d6be4f05b0a972 (patch) (side-by-side diff)
tree210b86e107b8a1241a0b563f97ad3b24bc7d7c97
parent4e1f50027c7d6fc59d47d932a2a37860e928ebb5 (diff)
downloadfile-backup-e975c3fd84c4b23b653b286739d6be4f05b0a972.tar.gz
file-backup-e975c3fd84c4b23b653b286739d6be4f05b0a972.tar.bz2
Rename package to File::BackupCopy
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile.PL6
-rw-r--r--lib/File/BackupCopy.pm (renamed from lib/File/Backup.pm)110
-rw-r--r--t/00simple.t14
-rw-r--r--t/01numbered.t12
-rw-r--r--t/02auto.t18
-rw-r--r--t/03backup.t28
-rw-r--r--t/04envar.t4
7 files changed, 96 insertions, 96 deletions
diff --git a/Makefile.PL b/Makefile.PL
index 84b1f32..1947389 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -4,9 +4,9 @@ use ExtUtils::MakeMaker;
use Module::Metadata;
WriteMakefile(
- NAME => 'File::Backup',
- VERSION_FROM => 'lib/File/Backup.pm',
- ABSTRACT_FROM => 'lib/File/Backup.pm',
+ NAME => 'File::BackupCopy',
+ VERSION_FROM => 'lib/File/BackupCopy.pm',
+ ABSTRACT_FROM => 'lib/File/BackupCopy.pm',
LICENSE => 'gpl_3',
AUTHOR => 'Sergey Poznyakoff <gray@gnu.org>',
MIN_PERL_VERSION => 5.006,
diff --git a/lib/File/Backup.pm b/lib/File/BackupCopy.pm
index 3bc18aa..b762e03 100644
--- a/lib/File/Backup.pm
+++ b/lib/File/BackupCopy.pm
@@ -1,4 +1,4 @@
-package File::Backup;
+package File::BackupCopy;
use strict;
use warnings;
use File::Copy;
@@ -17,9 +17,9 @@ our @EXPORT = qw(BACKUP_NONE
BACKUP_SIMPLE
BACKUP_NUMBERED
BACKUP_AUTO
- backup);
+ backup_copy);
-our @EXPORT_OK = qw(backup_simple backup_numbered backup_auto);
+our @EXPORT_OK = qw(backup_copy_simple backup_copy_numbered backup_copy_auto);
use constant {
BACKUP_NONE => 0, # No backups at all (none,off)
@@ -43,12 +43,12 @@ my %envtrans = (
my %backup_func = (
BACKUP_NONE() => sub {},
- BACKUP_SIMPLE() => \&backup_simple,
- BACKUP_NUMBERED() => \&backup_numbered,
- BACKUP_AUTO() => \&backup_auto
+ BACKUP_SIMPLE() => \&backup_copy_simple,
+ BACKUP_NUMBERED() => \&backup_copy_numbered,
+ BACKUP_AUTO() => \&backup_copy_auto
);
-sub backup {
+sub backup_copy {
my $file = shift;
my ($type, %opts);
@@ -72,7 +72,16 @@ sub backup {
&{$backup_func{$type}}($file, %opts);
}
-sub backup_simple {
+sub _backup_copy_error {
+ my ($error, $msg) = @_;
+ if ($error) {
+ $$error = $msg;
+ return undef;
+ }
+ confess $msg;
+}
+
+sub backup_copy_simple {
my $file_name = shift;
local %_ = @_;
my $error = delete $_{error};
@@ -83,21 +92,12 @@ sub backup_simple {
$backup_name = File::Spec->catfile($dir, $backup_name);
}
copy($file_name, $backup_name)
- or return _backup_error($error,
+ or return _backup_copy_error($error,
"failed to copy $file_name to $backup_name: $!");
return $backup_name;
}
-sub _backup_error {
- my ($error, $msg) = @_;
- if ($error) {
- $$error = $msg;
- return undef;
- }
- confess $msg;
-}
-
-sub backup_numbered_opt {
+sub backup_copy_internal {
my $file_name = shift;
my ($if_exists, $error, $dir);
@@ -115,11 +115,11 @@ sub backup_numbered_opt {
my $fh = eval { File::Temp->new(DIR => $dir || dirname($file_name)) };
if ($@) {
- return _backup_error($error, $@);
+ return _backup_copy_error($error, $@);
}
copy($file_name, $fh)
- or return _backup_error($error,
+ or return _backup_copy_error($error,
"failed to make a temporary copy of $file_name: $!");
my $pat = $dir ? File::Spec->catfile($dir, "$file_name.~*~")
@@ -134,7 +134,7 @@ sub backup_numbered_opt {
} glob($pat))[0];
if (!defined($num)) {
- return backup_simple($file_name, error => $error, dir => $dir)
+ return backup_copy_simple($file_name, error => $error, dir => $dir)
if $if_exists;
$num = '1';
}
@@ -147,7 +147,7 @@ sub backup_numbered_opt {
}
last if symlink($fh->filename, $backup_name);
unless ($!{EEXIST}) {
- return _backup_error("can't link "
+ return _backup_copy_error("can't link "
. $fh->filename .
" to $backup_name: $!");
}
@@ -155,21 +155,21 @@ sub backup_numbered_opt {
}
unless (rename($fh->filename, $backup_name)) {
- return _backup_error("can't rename temporary file to $backup_name: $!");
+ return _backup_copy_error("can't rename temporary file to $backup_name: $!");
}
return $backup_name;
}
-sub backup_numbered {
+sub backup_copy_numbered {
my ($file_name, %opts) = @_;
$opts{if_exists} = 0;
- backup_numbered_opt($file_name, %opts);
+ backup_copy_internal($file_name, %opts);
}
-sub backup_auto {
+sub backup_copy_auto {
my ($file_name, %opts) = @_;
$opts{if_exists} = 1;
- backup_numbered_opt($file_name, %opts);
+ backup_copy_internal($file_name, %opts);
}
1;
@@ -177,17 +177,17 @@ __END__
=head1 NAME
-File::Backup - create a backup of the file.
+File::BackupCopy - create a backup copy of the file.
=head1 SYNOPSIS
- use File::Backup;
+ use File::BackupCopy;
- $backup_name = backup($file_name);
+ $backup_name = backup_copy($file_name);
- $backup_name = backup($file_name, BACKUP_NUMBERED);
+ $backup_name = backup_copy($file_name, BACKUP_NUMBERED);
- $backup_name = backup($file_name, type => BACKUP_NUMBERED,
+ $backup_name = backup_copy($file_name, type => BACKUP_NUMBERED,
dir => $directory, error => \my $error);
if (!$backup_name) {
warn $error;
@@ -195,24 +195,24 @@ File::Backup - create a backup of the file.
=head1 DESCRIPTION
-The File::Backup module provides functions for creating backup copies of
+The File::BackupCopy module provides functions for creating backup copies of
files. Normally, the name of the backup copy is created by appending a
single C<~> character to the original file name. This naming is called
I<simple backup>. Another naming scheme is I<numbered backup>. In this
scheme, the name of the backup is created by suffixing the original file
name with C<.~I<N>~>, where I<N> is a decimal number starting with 1.
-In this backup naming scheme, the backup copies of file F<test> would be
+In this naming scheme, the backup copies of file F<test> would be
called F<test.~1~>, F<test.~2~> and so on.
-=head2 backup
+=head2 backup_copy
- $backup_name = backup($orig_name);
+ $backup_name = backup_copy($orig_name);
- $backup_name = backup($orig_name, $scheme);
+ $backup_name = backup_copy($orig_name, $scheme);
- $backup_name = backup($orig_name, %opts);
+ $backup_name = backup_copy($orig_name, %opts);
-The B<backup> function is the principal interface for managing backup
+The B<backup_copy> function is the principal interface for managing backup
copies. Its first argument specifies the name of the existing file for
which a backup copy is required. Optional second argument controls the
backup naming scheme. Its possible values are:
@@ -277,9 +277,9 @@ control the function behavior. The following arguments are understood:
Request a particular backup naming scheme. The following two calls are
equivalent:
- backup($file, type => BACKUP_SIMPLE)
+ backup_copy($file, type => BACKUP_SIMPLE)
- backup($file, BACKUP_SIMPLE)
+ backup_copy($file, BACKUP_SIMPLE)
=item dir =E<gt> $directory
@@ -296,9 +296,9 @@ a scalar) and C<undef> will be returned.
This can be used for an elaborate error handling and recovery, e.g.:
- $bname = backup($file, \my $err);
+ $bname = backup_copy($file, \my $err);
unless ($bname && defined($err)) {
- error("can't backup file $file: $err");
+ error("can't backup_copy file $file: $err");
# perhaps more code follows
}
...
@@ -308,31 +308,31 @@ This can be used for an elaborate error handling and recovery, e.g.:
The following functions are available for using a specific backup naming
scheme. These functions must be exported explicitly.
-=head2 backup_simple
+=head2 backup_copy_simple
- use File::Backup qw(backup_simple);
- $backup_name = backup_simple($orig_name, %opts);
+ use File::BackupCopy qw(backup_copy_simple);
+ $backup_name = backup_copy_simple($orig_name, %opts);
Creates simple backup. Optional I<%opts> have the same meaning as in
-B<backup>, except that, obviously, B<type> keyword is not accepted.
+B<backup_copy>, except that, obviously, B<type> keyword is not accepted.
-=head2 backup_numbered
+=head2 backup_copy_numbered
- use File::Backup qw(backup_numbered);
- $backup_name = backup_numbered($orig_name, %opts);
+ use File::BackupCopy qw(backup_copy_numbered);
+ $backup_name = backup_copy_numbered($orig_name, %opts);
Creates numbered backup. See above for a description of I<%opts>.
-=head2 backup_auto
+=head2 backup_copy_auto
- use File::Backup qw(backup_auto);
- $backup_name = backup_auto($orig_name, %opts);
+ use File::BackupCopy qw(backup_copy_auto);
+ $backup_name = backup_copy_auto($orig_name, %opts);
Creates numbered backup if any numbered backup version already exists for
the file. Otherwise, creates simple backup.
Optional I<%opts> have the same meaning as in
-B<backup>, except that, obviously, B<type> keyword is not accepted.
+B<backup_copy>, except that, obviously, B<type> keyword is not accepted.
=cut
diff --git a/t/00simple.t b/t/00simple.t
index bf4f71a..10faef6 100644
--- a/t/00simple.t
+++ b/t/00simple.t
@@ -2,36 +2,36 @@
use lib qw(t lib);
use strict;
use TestBackup;
-use File::Backup qw(backup_simple);
+use File::BackupCopy qw(backup_copy_simple);
plan test => 9;
makefile('a');
-my $name = backup_simple('a');
+my $name = backup_copy_simple('a');
ok($name, 'a~');
fileok('a', $name);
-$name = backup_simple('a');
+$name = backup_copy_simple('a');
ok($name, 'a~');
fileok('a', $name);
mkdir "subdir";
-$name = backup_simple('a', dir => 'subdir');
+$name = backup_copy_simple('a', dir => 'subdir');
ok($name, File::Spec->catfile('subdir','a~'));
fileok('a', $name);
eval {
- backup_simple('a', dir => 'nonexisting');
+ backup_copy_simple('a', dir => 'nonexisting');
};
ok(!!$@);
-$name = backup_simple('a', dir => 'nonexisting', error => \my $err);
+$name = backup_copy_simple('a', dir => 'nonexisting', error => \my $err);
ok(!defined($name));
ok(defined($err) && $err ne '');
# chmod 0, 'subdir';
-# $name = backup_simple('a', dir => 'subdir', error => \$err);
+# $name = backup_copy_simple('a', dir => 'subdir', error => \$err);
# ok(!defined($name));
# print "$err\n";
diff --git a/t/01numbered.t b/t/01numbered.t
index c4cd06a..50572c8 100644
--- a/t/01numbered.t
+++ b/t/01numbered.t
@@ -2,31 +2,31 @@
use lib qw(t lib);
use strict;
use TestBackup;
-use File::Backup qw(backup_numbered);
+use File::BackupCopy qw(backup_copy_numbered);
plan test => 9;
makefile('a');
-my $name = backup_numbered('a');
+my $name = backup_copy_numbered('a');
ok($name, 'a.~1~');
fileok('a', $name);
-$name = backup_numbered('a');
+$name = backup_copy_numbered('a');
ok($name, 'a.~2~');
fileok('a', $name);
mkdir "subdir";
-$name = backup_numbered('a', dir => 'subdir');
+$name = backup_copy_numbered('a', dir => 'subdir');
ok($name, File::Spec->catfile('subdir','a.~1~'));
fileok('a', $name);
eval {
- backup_numbered('a', dir => 'nonexisting');
+ backup_copy_numbered('a', dir => 'nonexisting');
};
ok(!!$@);
-$name = backup_numbered('a', dir => 'nonexisting', error => \my $err);
+$name = backup_copy_numbered('a', dir => 'nonexisting', error => \my $err);
ok(!defined($name));
ok(defined($err) && $err ne '');
diff --git a/t/02auto.t b/t/02auto.t
index 4717020..0a01d84 100644
--- a/t/02auto.t
+++ b/t/02auto.t
@@ -2,43 +2,43 @@
use lib qw(t lib);
use strict;
use TestBackup;
-use File::Backup qw(backup_numbered backup_auto);
+use File::BackupCopy qw(backup_copy_numbered backup_copy_auto);
plan test => 16;
makefile('a');
-my $name = backup_auto('a');
+my $name = backup_copy_auto('a');
ok($name, 'a~');
fileok('a', $name);
-$name = backup_numbered('a');
+$name = backup_copy_numbered('a');
ok($name, 'a.~1~');
fileok('a', $name);
-$name = backup_auto('a');
+$name = backup_copy_auto('a');
ok($name, 'a.~2~');
fileok('a', $name);
mkdir "subdir";
-$name = backup_auto('a', dir => 'subdir');
+$name = backup_copy_auto('a', dir => 'subdir');
ok($name, File::Spec->catfile('subdir','a~'));
fileok('a', $name);
-$name = backup_auto('a', dir => 'subdir');
+$name = backup_copy_auto('a', dir => 'subdir');
ok($name, File::Spec->catfile('subdir','a~'));
fileok('a', $name);
ok(open(FH, '>', File::Spec->catfile('subdir','a.~1~')));
-$name = backup_auto('a', dir => 'subdir');
+$name = backup_copy_auto('a', dir => 'subdir');
ok($name, File::Spec->catfile('subdir','a.~2~'));
fileok('a', $name);
eval {
- backup_auto('a', dir => 'nonexisting');
+ backup_copy_auto('a', dir => 'nonexisting');
};
ok(!!$@);
-$name = backup_auto('a', dir => 'nonexisting', error => \my $err);
+$name = backup_copy_auto('a', dir => 'nonexisting', error => \my $err);
ok(!defined($name));
ok(defined($err) && $err ne '');
diff --git a/t/03backup.t b/t/03backup.t
index 2b9297d..b040ba7 100644
--- a/t/03backup.t
+++ b/t/03backup.t
@@ -2,62 +2,62 @@
use lib qw(t lib);
use strict;
use TestBackup;
-use File::Backup;
+use File::BackupCopy;
plan test => 24;
makefile('a');
-my $name = backup('a',BACKUP_NONE);
+my $name = backup_copy('a',BACKUP_NONE);
ok(!defined($name));
-$name = backup('a',BACKUP_SIMPLE);
+$name = backup_copy('a',BACKUP_SIMPLE);
ok($name, 'a~');
fileok('a', $name);
-$name = backup('a',BACKUP_AUTO);
+$name = backup_copy('a',BACKUP_AUTO);
ok($name, 'a~');
fileok('a', $name);
-$name = backup('a',BACKUP_NUMBERED);
+$name = backup_copy('a',BACKUP_NUMBERED);
ok($name, 'a.~1~');
fileok('a', $name);
-$name = backup('a',BACKUP_AUTO);
+$name = backup_copy('a',BACKUP_AUTO);
ok($name, 'a.~2~');
fileok('a', $name);
-$name = backup('a');
+$name = backup_copy('a');
ok($name, 'a.~3~');
fileok('a', $name);
-$name = backup('a', type => BACKUP_SIMPLE);
+$name = backup_copy('a', type => BACKUP_SIMPLE);
ok($name, 'a~');
fileok('a', $name);
mkdir "subdir";
-$name = backup('a', dir => 'subdir', type => BACKUP_SIMPLE);
+$name = backup_copy('a', dir => 'subdir', type => BACKUP_SIMPLE);
ok($name, File::Spec->catfile('subdir','a~'));
fileok('a', $name);
-$name = backup('a', dir => 'subdir', type => BACKUP_AUTO);
+$name = backup_copy('a', dir => 'subdir', type => BACKUP_AUTO);
ok($name, File::Spec->catfile('subdir','a~'));
fileok('a', $name);
-$name = backup('a', dir => 'subdir', type => BACKUP_NUMBERED);
+$name = backup_copy('a', dir => 'subdir', type => BACKUP_NUMBERED);
ok($name, File::Spec->catfile('subdir','a.~1~'));
fileok('a', $name);
-$name = backup('a', dir => 'subdir', type => BACKUP_AUTO);
+$name = backup_copy('a', dir => 'subdir', type => BACKUP_AUTO);
ok($name, File::Spec->catfile('subdir','a.~2~'));
fileok('a', $name);
eval {
- backup('a', dir => 'nonexisting');
+ backup_copy('a', dir => 'nonexisting');
};
ok(!!$@);
-$name = backup('a', dir => 'nonexisting', error => \my $err);
+$name = backup_copy('a', dir => 'nonexisting', error => \my $err);
ok(!defined($name));
ok(defined($err) && $err ne '');
diff --git a/t/04envar.t b/t/04envar.t
index f87f355..f8f1761 100644
--- a/t/04envar.t
+++ b/t/04envar.t
@@ -2,7 +2,7 @@
use lib qw(t lib);
use strict;
use TestBackup;
-use File::Backup;
+use File::BackupCopy;
plan test => 16;
@@ -11,7 +11,7 @@ makefile('a');
sub test_envar {
my ($val, $exp) = @_;
$ENV{VERSION_CONTROL} = $val;
- my $name = backup('a');
+ my $name = backup_copy('a');
if (defined($exp)) {
ok($name,$exp);
fileok($name,'a');

Return to:

Send suggestions and report system problems to the System administrator.