BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 include_guard "temp_dir"
2  
3 template temp_dir {
4 objref_arg(_arg0) log;
5 alias(@_arg1) temp_base_dir;
6 alias(@_arg2) mktemp;
7 alias(@_arg3) rm;
8  
9 # Create a temporary directory.
10 var("") created_dir;
11 Do {
12 # Build the path template.
13 value(@concat(temp_base_dir, "/build-")) temp_prefix;
14 concat(temp_prefix, "XXXXXXXXXXXXXXXX") temp_template;
15  
16 # Call mktemp.
17 call(@run_process_output, {{mktemp, "-d", temp_template}}) mktemp_res;
18  
19 # Check mktemp success.
20 If (@not(mktemp_res.succeeded)) {
21 log->call(@error, "mktemp failed");
22 _do->break();
23 };
24  
25 # Remove a trailing newline from the output.
26 objref(^mktemp_res.output) output;
27 If (@num_equal(output.length, "0")) {
28 log->call(@error, "mktemp result is empty");
29 _do->break();
30 };
31 var(@num_subtract(output.length, "1")) len_minus_one;
32 output->substr(len_minus_one) last_char;
33 If (@val_different(last_char, "\n")) {
34 log->call(@error, "last char of mktemp result is not a newline");
35 _do->break();
36 };
37 output->substr("0", len_minus_one) without_newline;
38 output->reset(without_newline);
39  
40 # Check created dir prefix.
41 output->substr("0", temp_prefix.length) created_prefix;
42 If (@val_different(created_prefix, temp_prefix)) {
43 log->call(@error, "mktemp result prefix incorrect");
44 _do->break();
45 };
46  
47 # Remember it.
48 created_dir->set(output);
49 } Interrupt {
50 # Do not interrupt the directory creation, or we might
51 # end up with creating but not removing a directory.
52 if(@false);
53 } dir_creation;
54  
55 # Expose success status.
56 var(dir_creation.succeeded) succeeded;
57  
58 # Arrange for removing the temp dir.
59 If (succeeded) {
60 run({}, {rm, "-rf", created_dir});
61 };
62 }