aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2020-01-22 10:57:41 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2020-01-22 11:01:29 +0200
commit00c8b97d6e3fab6b87c9b3070bfb69f5858fe2b2 (patch)
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.
-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
@@ -91,3 +91,3 @@ sub backup_copy_simple {
if ($dir) {
- $backup_name = File::Spec->catfile($dir, $backup_name);
+ $backup_name = File::Spec->catfile($dir, basename($backup_name));
}
@@ -124,4 +124,5 @@ sub backup_copy_internal {
- 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 }
@@ -143,6 +144,3 @@ sub backup_copy_internal {
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);

Return to:

Send suggestions and report system problems to the System administrator.