summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2020-01-22 09:05:03 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2020-01-22 11:13:24 (GMT)
commitf3d76da04b7e918c104693b8584c4f4bd18a7c8d (patch) (side-by-side diff)
treeb53668b38e588552a775f3e6ffb6505e3d657605
parent00c8b97d6e3fab6b87c9b3070bfb69f5858fe2b2 (diff)
downloadfile-backup-f3d76da04b7e918c104693b8584c4f4bd18a7c8d.tar.gz
file-backup-f3d76da04b7e918c104693b8584c4f4bd18a7c8d.tar.bz2
Don't create temporary file if falling back to simple backup
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/File/BackupCopy.pm21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/File/BackupCopy.pm b/lib/File/BackupCopy.pm
index 43ce150..fd52029 100644
--- a/lib/File/BackupCopy.pm
+++ b/lib/File/BackupCopy.pm
@@ -113,18 +113,8 @@ sub backup_copy_internal {
croak "wrong number of arguments";
}
- my $fh = eval { File::Temp->new(DIR => $dir || dirname($file_name)) };
- if ($@) {
- return _backup_copy_error($error, $@);
- }
-
- copy($file_name, $fh)
- or return _backup_copy_error($error,
- "failed to make a temporary copy of $file_name: $!");
-
my $backup_stub = $dir ? File::Spec->catfile($dir, basename($file_name))
: $file_name;
- my $pat = "$backup_stub.~*~";
my $num = (sort { $b <=> $a }
map {
if (/.+\.~(\d+)~$/) {
@@ -132,7 +122,7 @@ sub backup_copy_internal {
} else {
()
}
- } glob($pat))[0];
+ } glob("$backup_stub.~*~"))[0];
if (!defined($num)) {
return backup_copy_simple($file_name, error => $error, dir => $dir)
@@ -140,6 +130,15 @@ sub backup_copy_internal {
$num = '1';
}
+ my $fh = eval { File::Temp->new(DIR => $dir || dirname($file_name)) };
+ if ($@) {
+ return _backup_copy_error($error, $@);
+ }
+
+ copy($file_name, $fh)
+ or return _backup_copy_error($error,
+ "failed to make a temporary copy of $file_name: $!");
+
my $backup_name;
while (1) {
$backup_name = "$backup_stub.~$num~";

Return to:

Send suggestions and report system problems to the System administrator.