File: build.rs

package info (click to toggle)
openvas-scanner 23.35.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 22,416 kB
  • sloc: ansic: 41,615; xml: 6,251; pascal: 3,723; yacc: 1,250; sh: 1,068; makefile: 333; sql: 273; javascript: 12
file content (54 lines) | stat: -rw-r--r-- 1,469 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::{
    fmt::Display,
    fs::{self, File},
    io::BufWriter,
    path::Path,
};

use flate2::{Compression, write::GzEncoder};
use tar::Builder;

fn create_test_layer(name: &str) -> Option<()> {
    fn ignore_error<O, E>(input: Result<O, E>) -> Option<O>
    where
        E: Display,
    {
        match input {
            Ok(x) => Some(x),
            Err(e) => {
                println!("cargo:warning={e}: Some tests may fail due to missing layer.");
                None
            }
        }
    }

    let input_dir = format!("test-data/images/{name}");
    let input_dir = Path::new(&input_dir);
    let output = format!("test-data/layers/{name}.tar.gz");
    let output_path = Path::new(&output);

    if !output_path.exists() {
        println!("cargo:info=Creating {output}");

        if let Some(parent_dir) = output_path.parent() {
            ignore_error(fs::create_dir_all(parent_dir))?;
        }
        let tar_gz = ignore_error(File::create(output_path))?;
        let enc = GzEncoder::new(BufWriter::new(tar_gz), Compression::default());
        let mut tar = Builder::new(enc);
        ignore_error(tar.append_dir_all(".", input_dir))?;
        ignore_error(ignore_error(tar.into_inner())?.finish())?;

        println!("cargo:info=Created {output}.");
    }
    Some(())
}

fn create_test_binaries() {
    create_test_layer("victim");
}

fn main() {
    //println!("cargo:rerun-if-changed=migrations");
    create_test_binaries();
}