diff options
author | Dmitry Bogatov <KAction@debian.org> | 2019-05-29 03:38:30 +0000 |
---|---|---|
committer | Dmitry Bogatov <KAction@debian.org> | 2019-05-29 03:38:30 +0000 |
commit | 80597efafb9943e53b566d9d0f6ee7a54a667b12 (patch) | |
tree | 6a2364fdd0d6d40bb8716d594b5791ce314aa74a | |
parent | e4b8e832194949b228db4fd00eab558dfc8b7d27 (diff) |
Refactor dh_runit
Introduce new function "create_empty_file" and reuse it for
side-effect of creating parent directories in
"template_from_data_directory" and to avoid manual open/close calls
in main function.
-rwxr-xr-x | dh_runit | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -12,6 +12,13 @@ use File::Slurp qw(read_file write_file); | |||
12 | use feature 'signatures'; | 12 | use feature 'signatures'; |
13 | no warnings 'experimental'; | 13 | no warnings 'experimental'; |
14 | 14 | ||
15 | # Create empty file {dest} and all required parent directories. | ||
16 | sub create_empty_file { | ||
17 | my ($dest) = @_; | ||
18 | make_path(dirname($dest)); | ||
19 | write_file($dest, '') || die $!; | ||
20 | } | ||
21 | |||
15 | # Render mustache template {name} from data directory into {dest}, | 22 | # Render mustache template {name} from data directory into {dest}, |
16 | # substituting {values} hash. If {perm} argument is provided, it is used | 23 | # substituting {values} hash. If {perm} argument is provided, it is used |
17 | # set permissions of {dest}. Intermediate directories to ${dest} are | 24 | # set permissions of {dest}. Intermediate directories to ${dest} are |
@@ -26,7 +33,7 @@ sub template_from_data_directory { | |||
26 | my $compiler = Text::Hogan::Compiler->new; | 33 | my $compiler = Text::Hogan::Compiler->new; |
27 | my $output = $compiler->compile($template)->render($values); | 34 | my $output = $compiler->compile($template)->render($values); |
28 | 35 | ||
29 | make_path(dirname($dest)); | 36 | create_empty_file($dest); |
30 | write_file($dest, $output); | 37 | write_file($dest, $output); |
31 | 38 | ||
32 | if (defined $perm) { | 39 | if (defined $perm) { |
@@ -86,10 +93,7 @@ PKG: foreach my $pkg (@{$dh{DOPACKAGES}}) { | |||
86 | my $name = $conf->{name} || basename($path); | 93 | my $name = $conf->{name} || basename($path); |
87 | 94 | ||
88 | if ($conf->{noreplace}) { | 95 | if ($conf->{noreplace}) { |
89 | make_path("${tmp}/usr/share/runit/meta/${name}/"); | 96 | create_empty_file("${tmp}/usr/share/runit/meta/${name}/noreplace"); |
90 | open(my $fh, ">", "${tmp}/usr/share/runit/meta/${name}/noreplace") | ||
91 | || die $!; | ||
92 | close($fh); | ||
93 | } | 97 | } |
94 | 98 | ||
95 | if ( -f $path) { | 99 | if ( -f $path) { |