diff options
author | Niels Thykier <niels@thykier.net> | 2017-06-13 18:27:45 +0000 |
---|---|---|
committer | Niels Thykier <niels@thykier.net> | 2017-06-13 18:27:45 +0000 |
commit | 79da6af50c03f4a2508b1a6c0336d86470e7dd58 (patch) | |
tree | 8996b48109fd7e227c97a2b28b1256b14660f34c | |
parent | d4ff9948a615fc9855a326d16487b26a317ced5e (diff) | |
download | debhelper-79da6af50c03f4a2508b1a6c0336d86470e7dd58.tar.gz |
Avoid forking for most renames
Signed-off-by: Niels Thykier <niels@thykier.net>
-rw-r--r-- | Debian/Debhelper/Dh_Lib.pm | 26 | ||||
-rwxr-xr-x | dh_bugfiles | 4 | ||||
-rwxr-xr-x | dh_builddeb | 4 |
3 files changed, 22 insertions, 12 deletions
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm index d764faf7..6de5d420 100644 --- a/Debian/Debhelper/Dh_Lib.pm +++ b/Debian/Debhelper/Dh_Lib.pm @@ -51,7 +51,7 @@ use vars qw(@EXPORT %dh); &generated_file &autotrigger &package_section &restore_file_on_clean &restore_all_files &open_gz &reset_perm_and_owner &deprecated_functionality - &log_installed_files &buildarch + &log_installed_files &buildarch &rename_path ); # The Makefile changes this if debhelper is installed in a PREFIX. @@ -377,6 +377,16 @@ sub install_dir { my @to_create = grep { not -d $_ } @_; doit('install', '-d', @to_create) if @to_create; } + +sub rename_path { + my ($source, $dest) = @_; + if (not rename($source, $dest)) { + my $files = escape_shell($source, $dest); + error("mv $files: $!") + } + return 1; +} + sub reset_perm_and_owner { my ($mode, @paths) = @_; doit('chmod', $mode, '--', @paths); @@ -727,7 +737,7 @@ sub autoscript { autoscript_sed($sed, $infile, "$outfile.new"); complex_doit("echo '# End automatically added section' >> $outfile.new"); complex_doit("cat $outfile >> $outfile.new"); - complex_doit("mv $outfile.new $outfile"); + rename_path("${outfile}.new", $outfile); } else { complex_doit("echo \"# Automatically added by ".basename($0)."\">> $outfile"); @@ -789,7 +799,7 @@ sub autoscript_sed { print {$ofd} "${trigger_type} ${trigger_target}\n"; close($ofd) or error("closing ${triggers_file}.new failed: $!"); close($ifd); - doit('mv', '-f', "${triggers_file}.new", $triggers_file); + rename_path("${triggers_file}.new", $triggers_file); } } @@ -813,7 +823,7 @@ sub delsubstvar { if (-e $substvarfile) { complex_doit("grep -a -s -v '^${substvar}=' $substvarfile > $substvarfile.new || true"); - doit("mv", "$substvarfile.new","$substvarfile"); + rename_path("${substvarfile}.new", $substvarfile); } } @@ -859,8 +869,8 @@ sub addsubstvar { } if (length $line) { - complex_doit("(grep -a -s -v ${substvar} $substvarfile; echo ".escape_shell("${substvar}=$line").") > $substvarfile.new"); - doit("mv", "$substvarfile.new", $substvarfile); + complex_doit("(grep -a -s -v ${substvar} $substvarfile; echo ".escape_shell("${substvar}=$line").") > $substvarfile.new"); + rename_path("$substvarfile.new", $substvarfile); } else { delsubstvar($package,$substvar); @@ -1510,7 +1520,7 @@ sub restore_file_on_clean { # Copy and then rename so we always have the full copy of # the file in the correct place (if any at all). doit('cp', '-an', '--reflink=auto', $file, "${bucket_dir}/${checksum}.tmp"); - doit('mv', '-f', "${bucket_dir}/${checksum}.tmp", "${bucket_dir}/${checksum}"); + rename_path("${bucket_dir}/${checksum}.tmp", "${bucket_dir}/${checksum}"); print {$fd} "${checksum} ${file}\n"; } close($fd) or error("close($bucket_index) failed: $!"); @@ -1538,7 +1548,7 @@ sub restore_all_files { # that with scary warnings) # 2) The file is always fully restored or in its "pre-restore" state. doit('cp', '-an', '--reflink=auto', $bucket_file, "${bucket_file}.tmp"); - doit('mv', '-Tf', "${bucket_file}.tmp", $stored_file); + rename_path("${bucket_file}.tmp", $stored_file); } close($fd); return; diff --git a/dh_bugfiles b/dh_bugfiles index 51fe1ff3..01e0bf46 100755 --- a/dh_bugfiles +++ b/dh_bugfiles @@ -103,9 +103,9 @@ foreach my $package (@{$dh{DOPACKAGES}}) { elsif (scalar(keys(%bugfiles)) > 0) { if (-f $dir) { # Move usr/share/bug/$package to usr/share/bug/$package/script - doit("mv", $dir, "${dir}.tmp"); + rename_path($dir, "${dir}.tmp"); install_dir($dir); - doit("mv", "${dir}.tmp", "$dir/script"); + rename_path("${dir}.tmp", "$dir/script"); } else { install_dir($dir); diff --git a/dh_builddeb b/dh_builddeb index 36e729dc..9d20dc7c 100755 --- a/dh_builddeb +++ b/dh_builddeb @@ -114,8 +114,8 @@ sub build_and_rename_deb { if ($desired_filename ne $dpkg_filename) { print "\tRenaming $dpkg_filename to $desired_filename\n"; } - doit('mv', '-f', "${build_dir}/${dpkg_filename}", - "${destdir}/${desired_filename}"); + rename_path("${build_dir}/${dpkg_filename}", + "${destdir}/${desired_filename}"); } foreach my $package (@{$dh{DOPACKAGES}}) { |