From a96d5a920b628609513e8ad83346ceb154eb38f5 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 22 Jun 2023 19:33:34 +1000 Subject: [PATCH] Add copy_file to anki_io, and ensure strings parent folder is created --- rslib/i18n/build/main.rs | 4 ++++ rslib/io/src/lib.rs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/rslib/i18n/build/main.rs b/rslib/i18n/build/main.rs index 197cd14da..d3fcfbe1e 100644 --- a/rslib/i18n/build/main.rs +++ b/rslib/i18n/build/main.rs @@ -6,6 +6,9 @@ mod extract; mod gather; mod write_strings; +use std::path::Path; + +use anki_io::create_dir_all; use anki_io::write_file_if_changed; use anyhow::Result; use check::check; @@ -26,6 +29,7 @@ fn main() -> Result<()> { println!("cargo:rerun-if-env-changed=STRINGS_JSON"); if let Some(path) = option_env!("STRINGS_JSON") { let meta_json = serde_json::to_string_pretty(&modules).unwrap(); + create_dir_all(Path::new(path).parent().unwrap())?; write_file_if_changed(path, meta_json)?; } Ok(()) diff --git a/rslib/io/src/lib.rs b/rslib/io/src/lib.rs index b28e19975..0beea0cbc 100644 --- a/rslib/io/src/lib.rs +++ b/rslib/io/src/lib.rs @@ -83,6 +83,14 @@ pub fn read_to_string(path: impl AsRef) -> Result { }) } +/// See [std::fs::copy]. +pub fn copy_file(src: impl AsRef, dst: impl AsRef) -> Result { + std::fs::copy(&src, &dst).context(FileIoSnafu { + path: dst.as_ref(), + op: FileOp::CopyFrom(src.as_ref().to_owned()), + }) +} + /// Like [read_file], but skips the section that is potentially locked by /// SQLite. pub fn read_locked_db_file(path: impl AsRef) -> Result> {