mirror of
https://github.com/github/codeql.git
synced 2025-12-17 09:13:20 +01:00
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.
29 lines
751 B
Rust
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(())
|
|
}
|
|
}
|