Shared: Handle trap compression option properly

Extracting the compression setting from an environment variable is the
responsibility of the API consumer.
This commit is contained in:
Harry Maclean
2023-04-27 05:03:22 +00:00
parent 9ea0b19ead
commit 8a89aec220
3 changed files with 9 additions and 2 deletions

View File

@@ -61,6 +61,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
},
],
trap_dir: options.output_dir,
trap_compression: trap::Compression::from_env("CODEQL_QL_TRAP_COMPRESSION"),
source_archive_dir: options.source_archive_dir,
file_list: options.file_list,
};

View File

@@ -22,6 +22,10 @@ pub struct Extractor {
pub trap_dir: PathBuf,
pub source_archive_dir: PathBuf,
pub file_list: PathBuf,
// Typically constructed via `trap::Compression::from_env`.
// This allow us to report the error using our diagnostics system
// without exposing it to consumers.
pub trap_compression: Result<trap::Compression, String>,
}
impl Extractor {
@@ -52,8 +56,8 @@ impl Extractor {
"threads"
}
);
let trap_compression = match trap::Compression::from_env("CODEQL_QL_TRAP_COMPRESSION") {
Ok(x) => x,
let trap_compression = match &self.trap_compression {
Ok(x) => *x,
Err(e) => {
main_thread_logger.write(
main_thread_logger

View File

@@ -3,6 +3,7 @@ use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use codeql_extractor::extractor::simple;
use codeql_extractor::trap;
use flate2::read::GzDecoder;
use tree_sitter_ql;
@@ -47,6 +48,7 @@ fn simple_extractor() {
trap_dir,
source_archive_dir,
file_list,
trap_compression: Ok(trap::Compression::Gzip),
};
// The extractor should run successfully