Add copy_file to anki_io, and ensure strings parent folder is created

This commit is contained in:
Damien Elmes 2023-06-22 19:33:34 +10:00
parent 1ae60a3bb0
commit a96d5a920b
2 changed files with 12 additions and 0 deletions

View file

@ -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(())

View file

@ -83,6 +83,14 @@ pub fn read_to_string(path: impl AsRef<Path>) -> Result<String> {
})
}
/// See [std::fs::copy].
pub fn copy_file(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<u64> {
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<Path>) -> Result<Vec<u8>> {