Files
codeql/rust/extractor/src/archive.rs
Nick Rolfe 665df4baef Ruby: add minimal path transformer support
Supports only a minimal subset of the project layout specification;
enough to work with the transformers produced by the CLI when building
an overlay database.
2025-06-19 16:34:16 +01:00

29 lines
751 B
Rust

use codeql_extractor::file_paths;
use std::fs;
use std::path::{Path, PathBuf};
use tracing::{debug, warn};
pub struct Archiver {
pub root: PathBuf,
}
impl Archiver {
pub fn archive(&self, source: &Path) {
if let Err(e) = self.try_archive(source) {
warn!("unable to archive {}: {e}", source.display());
}
}
fn try_archive(&self, source: &Path) -> std::io::Result<()> {
let dest = file_paths::path_for(&self.root, source, "", None);
if fs::metadata(&dest).is_ok() {
return Ok(());
}
let parent = dest.parent().unwrap();
fs::create_dir_all(parent)?;
fs::copy(source, dest)?;
debug!("archived {}", source.display());
Ok(())
}
}