diff options
author | Lars Wirzenius <liw@liw.fi> | 2024-01-26 19:29:11 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2024-01-26 19:29:11 +0200 |
commit | 974f72059c42ec32d138e9f05e94aa2bfbb8b019 (patch) | |
tree | da4d4bb0549b20e72d3e0980ac92a36e0411f877 | |
parent | 658ac7f4cf01a2cc240e5295dc7df9af5385a900 (diff) | |
download | ambient-driver-974f72059c42ec32d138e9f05e94aa2bfbb8b019.tar.gz |
feat: put artifacts into a per-project directory
Signed-off-by: Lars Wirzenius <liw@liw.fi>
Sponsored-by: author
-rw-r--r-- | src/project.rs | 5 | ||||
-rw-r--r-- | src/run.rs | 12 | ||||
-rw-r--r-- | src/util.rs | 11 | ||||
-rw-r--r-- | src/vdrive.rs | 8 |
4 files changed, 29 insertions, 7 deletions
diff --git a/src/project.rs b/src/project.rs index 2991d6b..658d075 100644 --- a/src/project.rs +++ b/src/project.rs @@ -178,6 +178,11 @@ impl State { Ok(()) } + /// Return artifacts directory for project. + pub fn artifactsdir(&self) -> PathBuf { + self.statedir.join("artifacts") + } + /// Return cache directory for project. pub fn cachedir(&self) -> PathBuf { self.statedir.join("cache") @@ -14,7 +14,7 @@ use crate::{ plan::{Plan, PlanError}, project::{Project, ProjectError, Projects, State}, qemu::{self, Qemu, QemuError}, - util::{changes_file, dput, mkdir, mkdir_child, rsync_server, UtilError}, + util::{changes_file, dput, mkdir, mkdir_child, recreate_dir, rsync_server, UtilError}, vdrive::{VirtualDriveBuilder, VirtualDriveError}, }; @@ -52,6 +52,9 @@ fn cmd_run(config: &EffectiveConfig, run: &RunCommand) -> Result<(), RunError> { if do_run { info!("{}: running CI on {}", name, project.source().display()); + let artifactsdir = state.artifactsdir(); + recreate_dir(&artifactsdir)?; + let cachedir = state.cachedir(); if !cachedir.exists() { mkdir(&cachedir)?; @@ -65,7 +68,6 @@ fn cmd_run(config: &EffectiveConfig, run: &RunCommand) -> Result<(), RunError> { debug!("Executing CI run"); let tmp = tempdir_in(config.stored_config().tmpdir()).map_err(RunError::TempDir)?; let artifact = tmp.path().join("artifact.tar"); - let staging = tmp.path().join("staging"); let run_ci_dir = mkdir_child(tmp.path(), "run-ci")?; assert!(run.run_ci().is_some()); @@ -110,7 +112,7 @@ fn cmd_run(config: &EffectiveConfig, run: &RunCommand) -> Result<(), RunError> { } let vdrive = VirtualDriveBuilder::default().filename(&artifact).open()?; - vdrive.extract_to(&staging)?; + vdrive.extract_to(&artifactsdir)?; if project.publish_artifacts() { if let Some(target) = run.target() { @@ -126,14 +128,14 @@ fn cmd_run(config: &EffectiveConfig, run: &RunCommand) -> Result<(), RunError> { if let Some(target) = rsync_target { debug!("publishing artifacts to {}", target); - rsync_server(&staging, target)?; + rsync_server(&artifactsdir, target)?; } else { debug!("not publishing artifacts: not requested"); } if let Some(target) = dput_target { debug!("publishing artifacts with dput {}", target); - let changes = changes_file(&staging)?; + let changes = changes_file(&artifactsdir)?; dput(target, &changes)?; } diff --git a/src/util.rs b/src/util.rs index 4b95106..ef7baee 100644 --- a/src/util.rs +++ b/src/util.rs @@ -34,6 +34,14 @@ pub fn mkdir_child(parent: &Path, subdir: &str) -> Result<PathBuf, UtilError> { Ok(pathname) } +pub fn recreate_dir(dirname: &Path) -> Result<(), UtilError> { + if dirname.exists() { + std::fs::remove_dir_all(dirname).map_err(|e| UtilError::RemoveDir(dirname.into(), e))?; + } + mkdir(&dirname)?; + Ok(()) +} + pub fn rsync_dir(src: &Path, dest: &Path) -> Result<(), UtilError> { let src = src.join("."); let dest = dest.join("."); @@ -164,4 +172,7 @@ pub enum UtilError { #[error("more than one *.changes file built for deb project")] ManyChanges, + + #[error("failed to remove directory {0}")] + RemoveDir(PathBuf, #[source] std::io::Error), } diff --git a/src/vdrive.rs b/src/vdrive.rs index 650235b..e2188fe 100644 --- a/src/vdrive.rs +++ b/src/vdrive.rs @@ -39,14 +39,18 @@ impl VirtualDrive { Ok(filenames) } - /// Extract files in the virtual drive into a new directory + /// Extract files in the virtual drive into a directory. Create + /// the directory if it doesn't exist. pub fn extract_to(&self, dirname: &Path) -> Result<(), VirtualDriveError> { debug!( "extracting {} to {}", self.filename.display(), dirname.display() ); - std::fs::create_dir(dirname).map_err(|e| VirtualDriveError::Extract(dirname.into(), e))?; + if !dirname.exists() { + std::fs::create_dir(dirname) + .map_err(|e| VirtualDriveError::Extract(dirname.into(), e))?; + } let file = File::open(&self.filename) .map_err(|e| VirtualDriveError::Open(self.filename.clone(), e))?; let mut archive = tar::Archive::new(file); |