mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Add copy_file to anki_io, and ensure strings parent folder is created
This commit is contained in:
parent
1ae60a3bb0
commit
a96d5a920b
2 changed files with 12 additions and 0 deletions
|
@ -6,6 +6,9 @@ mod extract;
|
||||||
mod gather;
|
mod gather;
|
||||||
mod write_strings;
|
mod write_strings;
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use anki_io::create_dir_all;
|
||||||
use anki_io::write_file_if_changed;
|
use anki_io::write_file_if_changed;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use check::check;
|
use check::check;
|
||||||
|
@ -26,6 +29,7 @@ fn main() -> Result<()> {
|
||||||
println!("cargo:rerun-if-env-changed=STRINGS_JSON");
|
println!("cargo:rerun-if-env-changed=STRINGS_JSON");
|
||||||
if let Some(path) = option_env!("STRINGS_JSON") {
|
if let Some(path) = option_env!("STRINGS_JSON") {
|
||||||
let meta_json = serde_json::to_string_pretty(&modules).unwrap();
|
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)?;
|
write_file_if_changed(path, meta_json)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -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
|
/// Like [read_file], but skips the section that is potentially locked by
|
||||||
/// SQLite.
|
/// SQLite.
|
||||||
pub fn read_locked_db_file(path: impl AsRef<Path>) -> Result<Vec<u8>> {
|
pub fn read_locked_db_file(path: impl AsRef<Path>) -> Result<Vec<u8>> {
|
||||||
|
|
Loading…
Reference in a new issue