Initial stabilization #1
1 changed files with 51 additions and 15 deletions
commit
96a929dff5
64
src/main.rs
64
src/main.rs
|
|
@ -23,6 +23,13 @@ struct Input {
|
|||
key: CacheKey,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum PathState {
|
||||
Unused,
|
||||
File,
|
||||
Directory,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// parse inputs
|
||||
let Input { path, key } = Input::get();
|
||||
|
|
@ -45,34 +52,63 @@ fn main() -> Result<()> {
|
|||
let mut archive = Archive::new(in_uncomp);
|
||||
let mut paths = path
|
||||
.into_iter()
|
||||
.map(|p| (p, true))
|
||||
.map(|p| (p, PathState::Unused))
|
||||
.collect::<HashMap<_, _>>();
|
||||
let mut entry_path = PathBuf::new();
|
||||
let mut directory_path = PathBuf::new();
|
||||
for entry in archive.entries().context("reading cache entries")? {
|
||||
let mut entry = entry.context("reading cache entry")?;
|
||||
entry_path.clear();
|
||||
entry_path.push(entry.path().context("reading entry path")?.as_ref());
|
||||
let Some(needs_unpacking) = paths.get_mut(&entry_path) else {
|
||||
println!(
|
||||
"warn: unknown entry in the archive: {}",
|
||||
entry_path.display()
|
||||
);
|
||||
continue;
|
||||
};
|
||||
if !core::mem::replace(needs_unpacking, false) {
|
||||
if let Some(state) = paths.get_mut(&entry_path) {
|
||||
// exact match on one of cached paths
|
||||
match core::mem::replace(state, PathState::File) {
|
||||
PathState::Unused => {
|
||||
entry.unpack(&entry_path).context("writing cache entry")?;
|
||||
}
|
||||
PathState::File => {
|
||||
println!(
|
||||
"warn: double entry in the archive: {}",
|
||||
entry_path.display()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
PathState::Directory => {
|
||||
println!(
|
||||
"WARN: found a regular file that was previously assumed to be a directory: {}",
|
||||
entry_path.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(directory) = paths.keys().find(|p| entry_path.starts_with(p)) {
|
||||
directory_path.clone_from(directory);
|
||||
// file in a cached directory
|
||||
let state = paths
|
||||
.get_mut(&directory_path)
|
||||
.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(&entry_path).context("writing cache entry")?;
|
||||
}
|
||||
|
||||
for (path, needs_unpacking) in paths {
|
||||
if needs_unpacking {
|
||||
PathState::File => {
|
||||
println!(
|
||||
"warn: requested cached path was not found in the cache entry: {}",
|
||||
"WARN: found a directory path that was previously assumed to be a regular file: {}",
|
||||
directory_path.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!(
|
||||
"warn: unmatched entry in the archive: {}",
|
||||
entry_path.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (path, state) in paths {
|
||||
if state == PathState::Unused {
|
||||
println!(
|
||||
"warn: cached path was not found in the cache: {}",
|
||||
path.display(),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue