summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2020-01-22 08:57:41 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2020-01-22 09:01:29 (GMT)
commit00c8b97d6e3fab6b87c9b3070bfb69f5858fe2b2 (patch) (side-by-side diff)
tree26049cbc1ca95e987f2583cc6f6d4ed0d10cd6dc
parent68be041dd11573aff08847748456040b9ef3f0b4 (diff)
downloadfile-backup-00c8b97d6e3fab6b87c9b3070bfb69f5858fe2b2.tar.gz
file-backup-00c8b97d6e3fab6b87c9b3070bfb69f5858fe2b2.tar.bz2
Optimize file creation loop
* lib/File/BackupCopy.pm (backup_copy_simple): Use base file name as the last argument to catfile. (backup_copy_internal): Compute backup file stub name before the loop.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/File/BackupCopy.pm12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/File/BackupCopy.pm b/lib/File/BackupCopy.pm
index 226e8ce..43ce150 100644
--- a/lib/File/BackupCopy.pm
+++ b/lib/File/BackupCopy.pm
@@ -89,7 +89,7 @@ sub backup_copy_simple {
croak "unrecognized keyword arguments" if keys %_;
my $backup_name = $file_name . '~';
if ($dir) {
- $backup_name = File::Spec->catfile($dir, $backup_name);
+ $backup_name = File::Spec->catfile($dir, basename($backup_name));
}
copy($file_name, $backup_name)
or return _backup_copy_error($error,
@@ -122,8 +122,9 @@ sub backup_copy_internal {
or return _backup_copy_error($error,
"failed to make a temporary copy of $file_name: $!");
- my $pat = $dir ? File::Spec->catfile($dir, "$file_name.~*~")
- : "$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+)~$/) {
@@ -141,10 +142,7 @@ sub backup_copy_internal {
my $backup_name;
while (1) {
- $backup_name = "$file_name.~$num~";
- if ($dir) {
- $backup_name = File::Spec->catfile($dir, $backup_name);
- }
+ $backup_name = "$backup_stub.~$num~";
last if symlink($fh->filename, $backup_name);
unless ($!{EEXIST}) {
return _backup_copy_error("can't link "

Return to:

Send suggestions and report system problems to the System administrator.