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,
|
key: CacheKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
enum PathState {
|
||||||
|
Unused,
|
||||||
|
File,
|
||||||
|
Directory,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
// parse inputs
|
// parse inputs
|
||||||
let Input { path, key } = Input::get();
|
let Input { path, key } = Input::get();
|
||||||
|
|
@ -45,34 +52,63 @@ fn main() -> Result<()> {
|
||||||
let mut archive = Archive::new(in_uncomp);
|
let mut archive = Archive::new(in_uncomp);
|
||||||
let mut paths = path
|
let mut paths = path
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| (p, true))
|
.map(|p| (p, PathState::Unused))
|
||||||
.collect::<HashMap<_, _>>();
|
.collect::<HashMap<_, _>>();
|
||||||
let mut entry_path = PathBuf::new();
|
let mut entry_path = PathBuf::new();
|
||||||
|
let mut directory_path = PathBuf::new();
|
||||||
for entry in archive.entries().context("reading cache entries")? {
|
for entry in archive.entries().context("reading cache entries")? {
|
||||||
let mut entry = entry.context("reading cache entry")?;
|
let mut entry = entry.context("reading cache entry")?;
|
||||||
entry_path.clear();
|
entry_path.clear();
|
||||||
entry_path.push(entry.path().context("reading entry path")?.as_ref());
|
entry_path.push(entry.path().context("reading entry path")?.as_ref());
|
||||||
let Some(needs_unpacking) = paths.get_mut(&entry_path) else {
|
if let Some(state) = paths.get_mut(&entry_path) {
|
||||||
println!(
|
// exact match on one of cached paths
|
||||||
"warn: unknown entry in the archive: {}",
|
match core::mem::replace(state, PathState::File) {
|
||||||
entry_path.display()
|
PathState::Unused => {
|
||||||
);
|
entry.unpack(&entry_path).context("writing cache entry")?;
|
||||||
continue;
|
}
|
||||||
};
|
PathState::File => {
|
||||||
if !core::mem::replace(needs_unpacking, false) {
|
|
||||||
println!(
|
println!(
|
||||||
"warn: double entry in the archive: {}",
|
"warn: double entry in the archive: {}",
|
||||||
entry_path.display()
|
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")?;
|
entry.unpack(&entry_path).context("writing cache entry")?;
|
||||||
}
|
}
|
||||||
|
PathState::File => {
|
||||||
for (path, needs_unpacking) in paths {
|
|
||||||
if needs_unpacking {
|
|
||||||
println!(
|
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(),
|
path.display(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue