summaryrefslogtreecommitdiff
path: root/subplotlib
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-30 11:30:32 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-30 11:30:32 +0000
commit21e3671ae5055b97023500a238098d162225953c (patch)
treeb147fa344ccfc1db44cbb5e3e06225afdc010035 /subplotlib
parent21f1db03313a211665f64b80a3c4127d018a591c (diff)
downloadsubplot-21e3671ae5055b97023500a238098d162225953c.tar.gz
subplotlib: Add open_write() to Datadir impl
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'subplotlib')
-rw-r--r--subplotlib/src/steplibrary/datadir.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/subplotlib/src/steplibrary/datadir.rs b/subplotlib/src/steplibrary/datadir.rs
index 69f79cf..1ef485e 100644
--- a/subplotlib/src/steplibrary/datadir.rs
+++ b/subplotlib/src/steplibrary/datadir.rs
@@ -5,6 +5,7 @@
//! If you want to create files, run commands, etc. from your scenarios, you
//! will likely be using them from within the datadir.
+use std::fs::{File, OpenOptions};
use std::path::{Component, Path, PathBuf};
pub use crate::prelude::*;
@@ -83,6 +84,17 @@ impl Datadir {
}
ret
}
+
+ /// Open a file for writing
+ #[throws(StepError)]
+ pub fn open_write<S: AsRef<Path>>(&self, subpath: S) -> File {
+ let full_path = self.canonicalise_filename(subpath)?;
+ OpenOptions::new()
+ .create(true)
+ .write(true)
+ .truncate(true)
+ .open(full_path)?
+ }
}
/// A simple check for enough disk space in the data dir