Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36
feat(cache): add output globs for cache restoration#375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
6d03bc0eb4ec37056bd46008f50aa7e4647f646282404bcd94bfa472015a9a690fdf91File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| //! Output archive creation and extraction using tar + zstd compression. | ||
| use std::{fs::File, io}; | ||
| use vite_path::{AbsolutePath, RelativePathBuf}; | ||
| /// Create a tar.zst archive from workspace-relative output file paths. | ||
| /// | ||
| /// Files that no longer exist are silently skipped (the task may delete | ||
| /// temporary files during execution). | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if creating the archive file or adding entries fails. | ||
| pub fn create_output_archive( | ||
| workspace_root: &AbsolutePath, | ||
| output_files: &[RelativePathBuf], | ||
| archive_path: &AbsolutePath, | ||
| ) -> anyhow::Result<()> { | ||
| let file = File::create(archive_path.as_path())?; | ||
| let encoder = zstd::Encoder::new(file, 0)?.auto_finish(); | ||
| let mut builder = tar::Builder::new(encoder); | ||
| for rel_path in output_files { | ||
| let abs_path = workspace_root.join(rel_path); | ||
| // Skip files that no longer exist (task may delete temp files between | ||
| // glob walk and archiving). Any other error is propagated. | ||
| let metadata = match std::fs::metadata(abs_path.as_path()) { | ||
| Ok(m) => m, | ||
| Err(err) if err.kind() == io::ErrorKind::NotFound => continue, | ||
| Err(err) => return Err(err.into()), | ||
| }; | ||
| if metadata.is_file() { | ||
| let mut file = File::open(abs_path.as_path())?; | ||
| let mut header = tar::Header::new_gnu(); | ||
| header.set_metadata(&metadata); | ||
| header.set_cksum(); | ||
| builder.append_data(&mut header, rel_path.as_str(), &mut file)?; | ||
| } | ||
| } | ||
| builder.finish()?; | ||
| Ok(()) | ||
| } | ||
| /// Extract a tar.zst archive, restoring files relative to workspace root. | ||
| /// | ||
| /// Parent directories are created automatically. Existing files are overwritten. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if opening the archive or extracting entries fails. | ||
| pub fn extract_output_archive( | ||
| workspace_root: &AbsolutePath, | ||
| archive_path: &AbsolutePath, | ||
| ) -> anyhow::Result<()> { | ||
| let file = File::open(archive_path.as_path())?; | ||
| let decoder = zstd::Decoder::new(file)?; | ||
| let mut archive = tar::Archive::new(decoder); | ||
| archive.unpack(workspace_root.as_path())?; | ||
| Ok(()) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.