summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2020-01-26 12:45:00 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2020-01-26 17:04:39 (GMT)
commitfc3de351597045aa9612379f2a0689b4b52393b7 (patch) (side-by-side diff)
tree89a3bdb5fb8516a77c689260031ab0d5fc3e8e9a
parent3b19782193f183b4f8285880eaa1c67ab816e50d (diff)
downloadfile-backup-nonsymlink.tar.gz
file-backup-nonsymlink.tar.bz2
Bugfixesnonsymlink
* lib/File/BackupCopy.pm (backup_copy_internal): Increase $num (rename_backup_win32): Use win32 error codes.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/File/BackupCopy.pm20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/File/BackupCopy.pm b/lib/File/BackupCopy.pm
index 25a839f..317abd9 100644
--- a/lib/File/BackupCopy.pm
+++ b/lib/File/BackupCopy.pm
@@ -10,7 +10,7 @@ use re '/aa';
use Carp;
use Errno;
-our $VERSION = '1.00_06';
+our $VERSION = '1.00_08';
our @ISA = qw(Exporter);
our @EXPORT = qw(BACKUP_NONE
BACKUP_SINGLE
@@ -124,7 +124,9 @@ sub backup_copy_internal {
}
} glob("$backup_stub.~*~"))[0];
- if (!defined($num)) {
+ if (defined($num)) {
+ ++$num;
+ } else {
return backup_copy_simple($file_name, error => $error, dir => $dir)
if $if_exists;
$num = '1';
@@ -172,7 +174,7 @@ BEGIN {
if (eval { symlink("",""); 1 }) {
*{rename_backup} = \&rename_backup_posix;
} elsif ($^O eq 'MSWin32' && eval { require Win32API::File }) {
- Win32API::File->import(qw(MoveFile));
+ Win32API::File->import(qw(MoveFile fileLastError));
*{rename_backup} = \&rename_backup_win32;
} else {
warn "using last resort rename method susceptible to a race condition";
@@ -208,9 +210,9 @@ sub rename_backup_posix {
return $backup_name;
}
-# rename_backup_win32 - rename_backup for MSWin32 systems with Win32::FileOp
+# rename_backup_win32 - rename_backup for MSWin32 systems with Win32API::File
# -------------------
-# This function is used if Win32::FileOp was loaded successfully. It uses
+# This function is used if Win32API::File was loaded successfully. It uses
# the MoveFile function to ensure atomic renames.
sub rename_backup_win32 {
my ($tempfilename, $backup_stub, $num, $error) = @_;
@@ -218,7 +220,11 @@ sub rename_backup_win32 {
while (1) {
$backup_name = "$backup_stub.~$num~";
last if MoveFile($tempfilename, $backup_name);
- unless ($!{EEXIST}) {
+ # 80 - ERROR_FILE_EXISTS
+ # - "The file exists."
+ # 183 - ERROR_ALREADY_EXISTS
+ # - "Cannot create a file when that file already exists."
+ unless (fileLastError() == 80 || fileLastError() == 183) {
return _backup_copy_error($error,
"can't rename $tempfilename to $backup_name: $^E");
}
@@ -230,7 +236,7 @@ sub rename_backup_win32 {
# rename_backup_last_resort - a weaker version for the rest of systems
# -------------------------
# It is enabled on systems not offering the symlink function (except where
-# Win32::FileOp can be used). This version uses a combination of -f test
+# Win32API::File can be used). This version uses a combination of -f test
# and rename. It suffers from an obvious race condition which occurs in
# the time window between these.
sub rename_backup_last_resort {

Return to:

Send suggestions and report system problems to the System administrator.