[tbb-commits] [rbm/master] Bug 28396: Create tmp files in rbm_tmp_dir instead of tmp_dir

gk at torproject.org gk at torproject.org
Mon Jul 5 07:49:46 UTC 2021


commit 8238f07edf404b82047fb09b76262e9a674ab146
Author: Nicolas Vigier <boklm at torproject.org>
Date:   Thu Jun 4 20:38:30 2020 +0200

    Bug 28396: Create tmp files in rbm_tmp_dir instead of tmp_dir
    
    rbm_tmp_dir is a directory inside tmp_dir that is automatically removed
    when rbm exits.
    
    We also fix an issue in urlget when used within the exec script of an
    input file. In this case the input_files_id was depending on the value
    of tmp_dir because it is used in urlget. We fix that be setting
    getting_input_files_id when computing input_files ids, so that urlget
    can avoid using tmp_dir in this case.
---
 doc/rbm_config.asc       |  7 +++++--
 lib/RBM.pm               | 19 +++++++------------
 lib/RBM/DefaultConfig.pm | 13 +++++++++++--
 3 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/doc/rbm_config.asc b/doc/rbm_config.asc
index 4c65a73..09776e4 100644
--- a/doc/rbm_config.asc
+++ b/doc/rbm_config.asc
@@ -223,8 +223,11 @@ input_files_id::
         filename to trigger a rebuild when any of its input files is
         changed. This identifier is based on: the +input_file_id+ option
         of an input file if it is present, the +filename+ for an input
-        file of type +project+, and the +filename+ and the sha256sum of
-        the file for any other type of input file.
+        file of type +project+, the value of +exec+ for an input file
+        of type +exec+, and the +filename+ and the sha256sum of the file
+        for any other type of input file. In the case of an input file
+        of type +exec+, the value of +exec+ is computed with +getting_id+
+        set to true.
 
 input_files_paths::
         The value of this option is an array of all the paths of input
diff --git a/lib/RBM.pm b/lib/RBM.pm
index d2aeab2..52b90ed 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -270,17 +270,11 @@ sub exit_error {
     exit (exists $_[1] ? $_[1] : 1);
 }
 
-sub get_tmp_dir {
-    my ($project, $options) = @_;
-    my $tmp_dir = project_config($project, 'tmp_dir', $options);
-    make_path($tmp_dir);
-    return $tmp_dir;
-}
-
 sub set_git_gpg_wrapper {
     my ($project) = @_;
     my $w = project_config($project, 'gpg_wrapper');
-    my (undef, $tmp) = File::Temp::tempfile(DIR => get_tmp_dir($project));
+    my (undef, $tmp) = File::Temp::tempfile(
+                        DIR => project_config($project, 'rbm_tmp_dir'));
     path($tmp)->spew_utf8($w);
     chmod 0700, $tmp;
     system('git', 'config', 'gpg.program', $tmp) == 0
@@ -342,7 +336,7 @@ sub git_tag_sign_id {
 sub file_sign_id {
     my ($project, $options) = @_;
     my (undef, $gpg_wrapper) = File::Temp::tempfile(DIR =>
-                                get_tmp_dir($project, $options));
+                                project_config($project, 'rbm_tmp_dir', $options));
     path($gpg_wrapper)->spew_utf8(project_config($project, 'gpg_wrapper', $options));
     chmod 0700, $gpg_wrapper;
     my ($stdout, $stderr, $success, $exit_code) =
@@ -576,7 +570,7 @@ sub maketar {
                 || exit_error 'Error running git archive.';
         if (project_config($project, 'git_submodule', $options)) {
             my $tmpdir = File::Temp->newdir(
-                get_tmp_dir($project, $options) . '/rbm-XXXXX');
+                project_config($project, 'rbm_tmp_dir', $options) . '/rbm-XXXXX');
             my ($stdout, $stderr, $success, $exit_code)
                 = capture_exec('git', 'checkout', $commit_hash);
             exit_error "Cannot checkout $commit_hash: $stderr" unless $success;
@@ -760,7 +754,8 @@ sub input_file_id {
     return $t->('input_file_id') if $input_file->{input_file_id};
     return $input_file->{project} . ':' . $filename if $input_file->{project};
     return $filename . ':' . $t->('sha256sum') if $input_file->{sha256sum};
-    return $filename . ':' . sha256_hex($t->('exec', { norec => { output_dir => '/out' } }))
+    my $opts = { norec => { output_dir => '/out', getting_id => 1, }};
+    return $filename . ':' . sha256_hex($t->('exec', $opts))
                 if $input_file->{exec};
     return input_file_id_hash($fname, $filename);
 }
@@ -1029,7 +1024,7 @@ sub build_run {
     valid_project($project);
     $options = { %$options, build_id => Data::UUID->new->create_str };
     my $old_cwd = getcwd;
-    my $tmpdir = File::Temp->newdir(get_tmp_dir($project, $options)
+    my $tmpdir = File::Temp->newdir(project_config($project, 'rbm_tmp_dir', $options)
                                 . '/rbm-XXXXX');
     my $srcdir = $tmpdir->dirname;
     my @cfiles;
diff --git a/lib/RBM/DefaultConfig.pm b/lib/RBM/DefaultConfig.pm
index c19d160..370f755 100644
--- a/lib/RBM/DefaultConfig.pm
+++ b/lib/RBM/DefaultConfig.pm
@@ -14,6 +14,7 @@ use RBM;
 use Cwd qw(getcwd);
 use IO::CaptureOutput qw(capture_exec);
 use File::Temp;
+use File::Path qw(make_path);
 
 sub lsb_release {
     my ($project, $options) = @_;
@@ -89,8 +90,9 @@ sub rbm_tmp_dir {
     my ($project, $options) = @_;
     CORE::state $rbm_tmp_dir;
     return $rbm_tmp_dir->dirname if $rbm_tmp_dir;
-    my $tmp_dir = RBM::get_tmp_dir($project, $options)
+    my $tmp_dir = RBM::project_config($project, 'tmp_dir', $options)
                   || RBM::exit_error('No tmp_dir specified');
+    make_path($tmp_dir);
     $rbm_tmp_dir = File::Temp->newdir(TEMPLATE => 'rbm-XXXXXX',
                                       DIR => $tmp_dir);
     return $rbm_tmp_dir->dirname;
@@ -397,7 +399,14 @@ OPT_END
     urlget => <<URLGET,
 #!/bin/sh
 set -e
-tmpfile="\$(mktemp -p [% shell_quote(c("tmp_dir")) %])"
+[%
+    IF c("getting_id");
+        SET rbm_tmp_dir = '/tmp';
+    ELSE;
+        SET rbm_tmp_dir = c("rbm_tmp_dir");
+    END;
+    -%]
+tmpfile="\$(mktemp -p [% shell_quote(rbm_tmp_dir) %])"
 wget -O"\$tmpfile" [% shell_quote(c("URL")) %]
 mv -f "\$tmpfile" [% shell_quote(dest_dir _ "/" _ c("filename")) %]
 URLGET





More information about the tbb-commits mailing list