[debhelper-devel] [debhelper] 01/02: Dh_Lib: Add "chdir" to the *_doit + doit API
Niels Thykier
nthykier at moszumanska.debian.org
Tue Sep 19 12:54:27 UTC 2017
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository debhelper.
commit 295211210d8b4bcac09f2efeb47223f779a90ff9
Author: Niels Thykier <niels at thykier.net>
Date: Tue Sep 19 12:37:17 2017 +0000
Dh_Lib: Add "chdir" to the *_doit + doit API
Signed-off-by: Niels Thykier <niels at thykier.net>
---
debian/changelog | 2 ++
doc/PROGRAMMING | 2 ++
lib/Debian/Debhelper/Dh_Lib.pm | 8 ++++++++
3 files changed, 12 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index bdc7e6d..7fb29db 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -25,6 +25,8 @@ debhelper (10.9) UNRELEASED; urgency=medium
* dh_fixperms: Set the permissions of /usr/lib/nodejs/*/{cli,bin}.js
to 0755. Thanks to Pirate Praveen for the report.
(Closes: #840913)
+ * Dh_lib.pm: Expand *_doit and doit to also support a chdir in the
+ child process.
[ Felipe Sateler ]
* dh_systemd_enable: Refactor and add support for timer units.
diff --git a/doc/PROGRAMMING b/doc/PROGRAMMING
index 5befe56..9067dfc 100644
--- a/doc/PROGRAMMING
+++ b/doc/PROGRAMMING
@@ -166,6 +166,8 @@ doit([$options, ]@command)
The following key-value pairs can be used:
* stdout => A file name. The child process will have its STDOUT redirected
to that file. [debhelper (>= 10.7)]
+ * chdir => A directory. The child process will do a chdir into that
+ directory before executing the command. [debhelper (>= 10.8)]
This will *not* invoke a shell, so meta characters will not have any special
meaning. Use complex_doit for that.
diff --git a/lib/Debian/Debhelper/Dh_Lib.pm b/lib/Debian/Debhelper/Dh_Lib.pm
index 80a6543..2dcacec 100644
--- a/lib/Debian/Debhelper/Dh_Lib.pm
+++ b/lib/Debian/Debhelper/Dh_Lib.pm
@@ -322,6 +322,11 @@ sub _doit {
my $pid = fork() // error("fork(): $!");
if (not $pid) {
if (defined($options)) {
+ if (defined(my $dir = $options->{chdir})) {
+ if ($dir ne '.') {
+ chdir($dir) or error("chdir(\"${dir}\) failed: $!");
+ }
+ }
if (defined(my $output = $options->{stdout})) {
open(STDOUT, '>', $output) or error("redirect STDOUT failed: $!");
}
@@ -337,6 +342,9 @@ sub _format_cmdline {
my (@cmd) = @_;
my $options = ref($cmd[0]) ? shift(@cmd) : {};
my $cmd_line = escape_shell(@cmd);
+ if (defined(my $dir = $options->{chdir})) {
+ $cmd_line = join(' ', 'cd', escape_shell($dir), '&&', $cmd_line) if $dir ne '.';
+ }
if (defined(my $output = $options->{stdout})) {
$cmd_line .= ' > ' . escape_shell($output);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git
More information about the debhelper-devel
mailing list