[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [Git][tpo/applications/rbm][main] Bug 40103: Allow having multiple tmp_dir values



Title: GitLab

boklm pushed to branch main at The Tor Project / Applications / RBM

Commits:

  • c88489dd
    by Nicolas Vigier at 2026-02-11T12:44:50+01:00
    Bug 40103: Allow having multiple tmp_dir values
    
    The `rbm_tmp_dir` function (and config option) is used to get a
    directory where temporary files can be stored. This directory is
    automatically removed when rbm exits, and its location is based on the
    `tmp_dir` config option. To return always the same directory and avoid
    creating a new one each time, a state variable is used, however that
    means that the value of the `tmp_dir` config option is ignored on
    following uses of `rbm_tmp_dir`. To fix that we change the state
    variable to be a hash variable, using `tmp_dir` as key. So that we
    create the temporary directory one time per value of `tmp_dir`.
    
    We are also adding a test to check the temporary directory from which we
    build is matching `tmp_dir` when we have two separate projects using a
    different value. The test was failing without the change and is now
    passing.
    

5 changed files:

Changes:

  • lib/RBM/DefaultConfig.pm
    ... ... @@ -88,14 +88,14 @@ sub docker_version {
    88 88
     
    
    89 89
     sub rbm_tmp_dir {
    
    90 90
         my ($project, $options) = @_;
    
    91
    -    CORE::state $rbm_tmp_dir;
    
    92
    -    return $rbm_tmp_dir->dirname if $rbm_tmp_dir;
    
    91
    +    CORE::state %rbm_tmp_dir;
    
    93 92
         my $tmp_dir = RBM::project_config($project, 'tmp_dir', $options)
    
    94 93
                       || RBM::exit_error('No tmp_dir specified');
    
    94
    +    return $rbm_tmp_dir{$tmp_dir}->dirname if $rbm_tmp_dir{$tmp_dir};
    
    95 95
         make_path($tmp_dir);
    
    96
    -    $rbm_tmp_dir = File::Temp->newdir(TEMPLATE => 'rbm-XXXXXX',
    
    96
    +    $rbm_tmp_dir{$tmp_dir} = File::Temp->newdir(TEMPLATE => 'rbm-XXXXXX',
    
    97 97
                                           DIR => $tmp_dir);
    
    98
    -    return $rbm_tmp_dir->dirname;
    
    98
    +    return $rbm_tmp_dir{$tmp_dir}->dirname;
    
    99 99
     }
    
    100 100
     
    
    101 101
     our %default_config = (
    

  • test.pl
    1 1
     #!/usr/bin/perl -w
    
    2 2
     use strict;
    
    3 3
     use Path::Tiny;
    
    4
    -use Test::More tests => 45;
    
    4
    +use Test::More tests => 46;
    
    5 5
     use lib 'lib/';
    
    6 6
     
    
    7 7
     sub set_target {
    
    ... ... @@ -282,6 +282,15 @@ my @tests = (
    282 282
             target => [ 'wrong_sha512sum' ],
    
    283 283
             fail_build  => [ 'shasum', 'build' ],
    
    284 284
         },
    
    285
    +    {
    
    286
    +        name   => 'setting different tmp_dir per project',
    
    287
    +        step   => 'build',
    
    288
    +        target => [],
    
    289
    +        build  => [ 'tmpdir_t1', 'build' ],
    
    290
    +        files  => {
    
    291
    +            'out/tmpdir_t1.txt' => "/var/tmp\n/tmp\n",
    
    292
    +        },
    
    293
    +    },
    
    285 294
     );
    
    286 295
     
    
    287 296
     foreach my $test (@tests) {
    

  • test/projects/tmpdir_t1/config
    1
    +filename: tmpdir_t1.txt
    
    2
    +tmp_dir: /tmp
    
    3
    +build: |
    
    4
    +  #!/bin/sh
    
    5
    +  set -e
    
    6
    +  cat tmpdir_t2.txt tmpdir_t3.txt > [% dest_dir %]/[% c('filename') %]
    
    7
    +input_files:
    
    8
    +  - project: tmpdir_t2
    
    9
    +    refresh_input: 1
    
    10
    +  - project: tmpdir_t3
    
    11
    +    refresh_input: 1

  • test/projects/tmpdir_t2/config
    1
    +filename: tmpdir_t2.txt
    
    2
    +tmp_dir: /var/tmp
    
    3
    +build: |
    
    4
    +  #!/bin/sh
    
    5
    +  set -e
    
    6
    +  dir=$(dirname $(dirname $(pwd)))
    
    7
    +  test "$dir" = '[% c("tmp_dir") %]'
    
    8
    +  echo "$dir" > [% dest_dir %]/[% c('filename') %]

  • test/projects/tmpdir_t3/config
    1
    +filename: tmpdir_t3.txt
    
    2
    +tmp_dir: /tmp
    
    3
    +build: |
    
    4
    +  #!/bin/sh
    
    5
    +  set -e
    
    6
    +  dir=$(dirname $(dirname $(pwd)))
    
    7
    +  test "$dir" = '[% c("tmp_dir") %]'
    
    8
    +  echo "$dir" > [% dest_dir %]/[% c('filename') %]

  • _______________________________________________
    tor-commits mailing list -- tor-commits@xxxxxxxxxxxxxxxxxxxx
    To unsubscribe send an email to tor-commits-leave@xxxxxxxxxxxxxxxxxxxx