Initial stabilization #1

Merged
dzu merged 11 commits from stabilize-v1 into master 2026-02-21 04:17:06 +01:00
Showing only changes of commit 96a929dff5 - Show all commits

fix: restoring files from cached directory
All checks were successful
Build and update the action / build-and-upload (push) Successful in 2m34s

Artem Diachenko 2026-02-20 11:05:06 +00:00

View file

@ -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 {
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()
);
}
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")?;
}
PathState::File => {
println!(
"WARN: found a directory path that was previously assumed to be a regular file: {}",
directory_path.display()
);
}
}
} else {
println!(
"warn: unknown entry in the archive: {}",
"warn: unmatched entry in the archive: {}",
entry_path.display()
);
continue;
};
if !core::mem::replace(needs_unpacking, false) {
println!(
"warn: double entry in the archive: {}",
entry_path.display()
);
continue;
}
entry.unpack(&entry_path).context("writing cache entry")?;
}
for (path, needs_unpacking) in paths {
if needs_unpacking {
for (path, state) in paths {
if state == PathState::Unused {
println!(
"warn: requested cached path was not found in the cache entry: {}",
"warn: cached path was not found in the cache: {}",
path.display(),
);
}