diff --git a/Cargo.lock b/Cargo.lock index ccaf74f..0c7b976 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "anode" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros", "thiserror", @@ -20,7 +20,7 @@ dependencies = [ [[package]] name = "anode-build" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros-input", "quote", @@ -32,7 +32,7 @@ dependencies = [ [[package]] name = "anode-cache-common" version = "0.1.0" -source = "git+https://git.dzuchun.ing/actions/cache-common-src.git#479d6fe4149b1cc4c81486fdf0eb6f6a56fc9282" +source = "git+https://git.dzuchun.ing/actions/cache-common-src.git?tag=v3#a460ddb58f8b2006a9edfd231d12882cc95bcca0" dependencies = [ "anyhow", "isahc", @@ -46,7 +46,7 @@ dependencies = [ [[package]] name = "anode-macros" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "anode-macros-input", "proc-macro2", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "anode-macros-input" version = "0.1.0" -source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b" +source = "git+https://git.dzuchun.ing/dzu/anode.git?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 744a65b..0c6a8a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,16 +4,23 @@ version = "0.1.0" edition = "2024" [dependencies] -anode = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } -anode-cache-common = { git = "https://git.dzuchun.ing/actions/cache-common-src.git", version = "0.1.0" } anyhow = "1.0.101" flate2 = "1.1.9" secrecy = "0.10.3" tar = "0.4.44" tracing = { version = "0.1.44", features = ["attributes"] } -[build-dependencies] -anode-build = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" } +[dependencies.anode] +git = "https://git.dzuchun.ing/dzu/anode.git" +tag = "v1" + +[dependencies.anode-cache-common] +git = "https://git.dzuchun.ing/actions/cache-common-src.git" +tag = "v3" + +[build-dependencies.anode-build] +git = "https://git.dzuchun.ing/dzu/anode.git" +tag = "v1" [profile.release] opt-level = "s" diff --git a/src/main.rs b/src/main.rs index 4b91110..dbae290 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,25 +59,26 @@ fn main() -> Result<()> { let in_uncomp = GzDecoder::new(&mut cache); let mut archive = Archive::new(in_uncomp); - debug!(paths = ?path); - let mut paths = path - .into_iter() - .map(|p| (p, PathState::Unused)) + let common = anode_cache_common::common_parent(&path); + debug!(common_path = %common.display(), paths = ?path); + let mut names = path + .iter() + .map(|p| (p.strip_prefix(&common).unwrap(), (p, PathState::Unused))) .collect::>(); // tmp buffers - let mut entry_path_buf = PathBuf::new(); - let mut directory_path_buf = PathBuf::new(); + let mut entry_name_buf = PathBuf::new(); + let mut directory_name_buf = PathBuf::new(); for entry in archive.entries().context("reading cache entries")? { let mut entry = entry.context("reading cache entry")?; { - let entry_path = entry.path().context("reading entry path")?; - entry_path_buf.clear(); - entry_path_buf.push(&entry_path); + let entry_name = entry.path().context("reading entry path")?; + entry_name_buf.clear(); + entry_name_buf.push(&entry_name); } - let _span = info_span!("archive-entry", path = %entry_path_buf.display()); + let _span = info_span!("archive-entry", name = %entry_name_buf.display()); let _span = _span.enter(); - if let Some(state) = paths.get_mut(&entry_path_buf) { + if let Some((output_path, state)) = names.get_mut(&*entry_name_buf) { let new_state = if entry.header().entry_type().is_dir() { PathState::Directory } else { @@ -87,9 +88,7 @@ fn main() -> Result<()> { // match on (old, new) match (core::mem::replace(state, new_state), new_state) { (PathState::Unused, _) => { - entry - .unpack(&entry_path_buf) - .context("writing cache entry")?; + entry.unpack(*output_path).context("writing cache entry")?; debug!("Unpacked normally"); } (PathState::File, PathState::File) => { @@ -107,18 +106,17 @@ fn main() -> Result<()> { } (_, PathState::Unused) => unreachable!(), } - } else if let Some(directory) = paths.keys().find(|p| entry_path_buf.starts_with(p)) { + } else if let Some(directory) = names.keys().find(|p| entry_name_buf.starts_with(p)) { debug!(directory = %directory.display(), "File in a directory"); - directory_path_buf.clone_from(directory); + directory_name_buf.clear(); + directory_name_buf.push(directory); // file in a cached directory - let state = paths - .get_mut(&directory_path_buf) - .expect("paths should contain a path that was just extracted as a key"); + let (output_path, state) = names + .get_mut(&*directory_name_buf) + .expect("name should contain a name that was just extracted as a key"); match core::mem::replace(state, PathState::Directory) { PathState::Unused | PathState::Directory => { - entry - .unpack(&entry_path_buf) - .context("writing cache entry")?; + entry.unpack(*output_path).context("writing cache entry")?; debug!("Unpacked normally"); } PathState::File => { @@ -130,9 +128,9 @@ fn main() -> Result<()> { } } - for (path, state) in paths { + for (path, (name, state)) in names { if state == PathState::Unused { - warn!(path = %path.display(), "Cached path was not found in the cache",); + warn!(path = %path.display(), name = %name.display(), "Cached path was not found in the cache",); } }