Skip to content

Commit 8a89aec

Browse files
committed
Shared: Handle trap compression option properly
Extracting the compression setting from an environment variable is the responsibility of the API consumer.
1 parent 9ea0b19 commit 8a89aec

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

ql/extractor/src/extractor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
6161
},
6262
],
6363
trap_dir: options.output_dir,
64+
trap_compression: trap::Compression::from_env("CODEQL_QL_TRAP_COMPRESSION"),
6465
source_archive_dir: options.source_archive_dir,
6566
file_list: options.file_list,
6667
};

shared/tree-sitter-extractor/src/extractor/simple.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ pub struct Extractor {
2222
pub trap_dir: PathBuf,
2323
pub source_archive_dir: PathBuf,
2424
pub file_list: PathBuf,
25+
// Typically constructed via `trap::Compression::from_env`.
26+
// This allow us to report the error using our diagnostics system
27+
// without exposing it to consumers.
28+
pub trap_compression: Result<trap::Compression, String>,
2529
}
2630

2731
impl Extractor {
@@ -52,8 +56,8 @@ impl Extractor {
5256
"threads"
5357
}
5458
);
55-
let trap_compression = match trap::Compression::from_env("CODEQL_QL_TRAP_COMPRESSION") {
56-
Ok(x) => x,
59+
let trap_compression = match &self.trap_compression {
60+
Ok(x) => *x,
5761
Err(e) => {
5862
main_thread_logger.write(
5963
main_thread_logger

shared/tree-sitter-extractor/tests/integration_test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::io::{Read, Write};
33
use std::path::{Path, PathBuf};
44

55
use codeql_extractor::extractor::simple;
6+
use codeql_extractor::trap;
67
use flate2::read::GzDecoder;
78
use tree_sitter_ql;
89

@@ -47,6 +48,7 @@ fn simple_extractor() {
4748
trap_dir,
4849
source_archive_dir,
4950
file_list,
51+
trap_compression: Ok(trap::Compression::Gzip),
5052
};
5153

5254
// The extractor should run successfully

0 commit comments

Comments
 (0)