Compare commits
3 changed files with 33 additions and 38 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -11,7 +11,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
|||
[[package]]
|
||||
name = "anode"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.dzuchun.ing/dzu/anode.git?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b"
|
||||
source = "git+https://git.dzuchun.ing/dzu/anode.git#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?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b"
|
||||
source = "git+https://git.dzuchun.ing/dzu/anode.git#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?tag=v3#a460ddb58f8b2006a9edfd231d12882cc95bcca0"
|
||||
source = "git+https://git.dzuchun.ing/actions/cache-common-src.git#479d6fe4149b1cc4c81486fdf0eb6f6a56fc9282"
|
||||
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?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b"
|
||||
source = "git+https://git.dzuchun.ing/dzu/anode.git#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?tag=v1#98addf4d54ae16c21979a1dae63d17738b3a277b"
|
||||
source = "git+https://git.dzuchun.ing/dzu/anode.git#98addf4d54ae16c21979a1dae63d17738b3a277b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
|||
15
Cargo.toml
15
Cargo.toml
|
|
@ -4,23 +4,16 @@ 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"] }
|
||||
|
||||
[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"
|
||||
[build-dependencies]
|
||||
anode-build = { git = "https://git.dzuchun.ing/dzu/anode.git", version = "0.1.0" }
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s"
|
||||
|
|
|
|||
46
src/main.rs
46
src/main.rs
|
|
@ -59,26 +59,25 @@ fn main() -> Result<()> {
|
|||
let in_uncomp = GzDecoder::new(&mut cache);
|
||||
let mut archive = Archive::new(in_uncomp);
|
||||
|
||||
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)))
|
||||
debug!(paths = ?path);
|
||||
let mut paths = path
|
||||
.into_iter()
|
||||
.map(|p| (p, PathState::Unused))
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
// tmp buffers
|
||||
let mut entry_name_buf = PathBuf::new();
|
||||
let mut directory_name_buf = PathBuf::new();
|
||||
let mut entry_path_buf = PathBuf::new();
|
||||
let mut directory_path_buf = PathBuf::new();
|
||||
for entry in archive.entries().context("reading cache entries")? {
|
||||
let mut entry = entry.context("reading cache entry")?;
|
||||
{
|
||||
let entry_name = entry.path().context("reading entry path")?;
|
||||
entry_name_buf.clear();
|
||||
entry_name_buf.push(&entry_name);
|
||||
let entry_path = entry.path().context("reading entry path")?;
|
||||
entry_path_buf.clear();
|
||||
entry_path_buf.push(&entry_path);
|
||||
}
|
||||
let _span = info_span!("archive-entry", name = %entry_name_buf.display());
|
||||
let _span = info_span!("archive-entry", path = %entry_path_buf.display());
|
||||
let _span = _span.enter();
|
||||
if let Some((output_path, state)) = names.get_mut(&*entry_name_buf) {
|
||||
if let Some(state) = paths.get_mut(&entry_path_buf) {
|
||||
let new_state = if entry.header().entry_type().is_dir() {
|
||||
PathState::Directory
|
||||
} else {
|
||||
|
|
@ -88,7 +87,9 @@ fn main() -> Result<()> {
|
|||
// match on (old, new)
|
||||
match (core::mem::replace(state, new_state), new_state) {
|
||||
(PathState::Unused, _) => {
|
||||
entry.unpack(*output_path).context("writing cache entry")?;
|
||||
entry
|
||||
.unpack(&entry_path_buf)
|
||||
.context("writing cache entry")?;
|
||||
debug!("Unpacked normally");
|
||||
}
|
||||
(PathState::File, PathState::File) => {
|
||||
|
|
@ -106,17 +107,18 @@ fn main() -> Result<()> {
|
|||
}
|
||||
(_, PathState::Unused) => unreachable!(),
|
||||
}
|
||||
} else if let Some(directory) = names.keys().find(|p| entry_name_buf.starts_with(p)) {
|
||||
} else if let Some(directory) = paths.keys().find(|p| entry_path_buf.starts_with(p)) {
|
||||
debug!(directory = %directory.display(), "File in a directory");
|
||||
directory_name_buf.clear();
|
||||
directory_name_buf.push(directory);
|
||||
directory_path_buf.clone_from(directory);
|
||||
// file in a cached directory
|
||||
let (output_path, state) = names
|
||||
.get_mut(&*directory_name_buf)
|
||||
.expect("name should contain a name that was just extracted as a key");
|
||||
let state = paths
|
||||
.get_mut(&directory_path_buf)
|
||||
.expect("paths should contain a path that was just extracted as a key");
|
||||
match core::mem::replace(state, PathState::Directory) {
|
||||
PathState::Unused | PathState::Directory => {
|
||||
entry.unpack(*output_path).context("writing cache entry")?;
|
||||
entry
|
||||
.unpack(&entry_path_buf)
|
||||
.context("writing cache entry")?;
|
||||
debug!("Unpacked normally");
|
||||
}
|
||||
PathState::File => {
|
||||
|
|
@ -128,9 +130,9 @@ fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
for (path, (name, state)) in names {
|
||||
for (path, state) in paths {
|
||||
if state == PathState::Unused {
|
||||
warn!(path = %path.display(), name = %name.display(), "Cached path was not found in the cache",);
|
||||
warn!(path = %path.display(), "Cached path was not found in the cache",);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue