summaryrefslogtreecommitdiff
path: root/subplotlib
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-30 11:30:50 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-30 11:30:50 +0000
commit8704ec0f4a9052ef1344692349e36c8118ea5702 (patch)
tree5e48fe6b01b86e8e77cdc5c98fec6161fab7f210 /subplotlib
parent21e3671ae5055b97023500a238098d162225953c (diff)
downloadsubplot-8704ec0f4a9052ef1344692349e36c8118ea5702.tar.gz
subplotlib: Use open_write() and fix bug in remember_metadata
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'subplotlib')
-rw-r--r--subplotlib/src/steplibrary/files.rs26
1 files changed, 12 insertions, 14 deletions
diff --git a/subplotlib/src/steplibrary/files.rs b/subplotlib/src/steplibrary/files.rs
index 180fbee..f940f08 100644
--- a/subplotlib/src/steplibrary/files.rs
+++ b/subplotlib/src/steplibrary/files.rs
@@ -41,13 +41,9 @@ pub fn create_from_embedded_with_other_name(
filename_on_disk: &str,
embedded_file: SubplotDataFile,
) {
- let full_path = context.canonicalise_filename(filename_on_disk)?;
- let mut f = OpenOptions::new()
- .create(true)
- .write(true)
- .truncate(true)
- .open(full_path)?;
- f.write_all(embedded_file.data())?;
+ context
+ .open_write(filename_on_disk)?
+ .write_all(embedded_file.data())?;
}
#[step]
@@ -69,13 +65,7 @@ pub fn touch_with_timestamp(context: &Datadir, filename: &str, mtime: &str) {
#[step]
pub fn create_from_text(context: &Datadir, text: &str, filename: &str) {
- let full_path = context.canonicalise_filename(filename)?;
- let mut f = OpenOptions::new()
- .create(true)
- .write(true)
- .truncate(true)
- .open(full_path)?;
- f.write_all(text.as_bytes())?;
+ context.open_write(filename)?.write_all(text.as_bytes())?;
}
#[step]
@@ -100,6 +90,14 @@ pub fn remember_metadata(context: &ScenarioContext, filename: &str) {
pub fn touch(context: &Datadir, filename: &str) {
let full_path = context.canonicalise_filename(filename)?;
let now = FileTime::now();
+ // If the file doesn't exist, create it
+ drop(
+ OpenOptions::new()
+ .create(true)
+ .write(true)
+ .open(&full_path)?,
+ );
+ // And set its mtime
filetime::set_file_mtime(full_path, now)?;
}