mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
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:
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user