bindings_generat/sources/
mod.rs1pub mod archives;
2
3use anyhow::Result;
4use std::path::PathBuf;
5
6pub fn prepare_source(source: &str) -> Result<PreparedSource> {
11 if source.starts_with("http://") || source.starts_with("https://") {
13 return archives::download_and_extract(source);
14 }
15
16 let path = PathBuf::from(source);
17
18 if path.is_file() {
20 return archives::extract_archive(&path);
21 }
22
23 if path.is_dir() {
25 return Ok(PreparedSource {
26 path,
27 is_temporary: false,
28 });
29 }
30
31 anyhow::bail!("Source path does not exist: {}", source);
32}
33
34pub struct PreparedSource {
36 pub path: PathBuf,
38
39 pub is_temporary: bool,
41}
42
43impl PreparedSource {
44 pub fn path(&self) -> &PathBuf {
46 &self.path
47 }
48}
49
50impl Drop for PreparedSource {
51 fn drop(&mut self) {
52 if self.is_temporary {
53 if let Err(e) = std::fs::remove_dir_all(&self.path) {
55 tracing::warn!(
56 "Failed to clean up temporary directory {}: {}",
57 self.path.display(),
58 e
59 );
60 }
61 }
62 }
63}