Only rewrite changed files
Dependencies
- [2]
R524JUUEImplement metadata & price directives - [3]
SJ6AFVZLremove const configuration in favor of runtime config - [4]
MG46NYACenable deserialization of configuration for common utilities - [5]
2NYDNXH7Use OS dependent path separator when constructing paths in tree writer - [6]
D6UTHZA4add a simple writer for saving a set of directives to a tree of files - [*]
2JBFREZGenable additional warnings
Change contents
- edit in common/beancount-tree-writer/src/lib.rs at line 8[8.16504][3.0]
use std::io::Read;use std::io::Write; - replacement in common/beancount-tree-writer/src/lib.rs at line 86
file: &Utf8Path,path: &Utf8Path, - replacement in common/beancount-tree-writer/src/lib.rs at line 100[3.979]→[2.13942:13971](∅→∅),[2.13971]→[3.2544:2575](∅→∅),[3.2544]→[3.2544:2575](∅→∅),[3.2575]→[3.1040:1139](∅→∅),[3.234]→[3.2667:2682](∅→∅),[3.1139]→[3.2667:2682](∅→∅),[3.2667]→[3.2667:2682](∅→∅),[3.2682]→[2.13972:14023](∅→∅),[2.14023]→[3.2740:2876](∅→∅),[3.2740]→[3.2740:2876](∅→∅),[3.2876]→[3.2876:2877](∅→∅),[3.2877]→[3.291:323](∅→∅),[3.323]→[3.2928:2934](∅→∅),[3.2928]→[3.2928:2934](∅→∅)
self.open_file(file).and_then(|file| {PrettyPrinter::buffered(pretty_printer_config, file).print_directives(&directives)}).context(PrettyPrintingSnafu { file })}fn open_file(&self, file_path: &Utf8Path) -> io::Result<File> {self.ensure_directory(file_path.parent().unwrap())?;File::create(file_path)}let mut buffer = Vec::new();PrettyPrinter::unbuffered(pretty_printer_config, &mut buffer).print_directives(&directives).and_then(|_| update_file(path, &buffer)).context(PrettyPrintingSnafu { file: path })?; - replacement in common/beancount-tree-writer/src/lib.rs at line 106
fn ensure_directory(&self, directory: &Utf8Path) -> io::Result<()> {fs::create_dir_all(directory)Ok(()) - edit in common/beancount-tree-writer/src/lib.rs at line 178[8.16866]
fn ensure_directory(directory: &Utf8Path) -> io::Result<()> {fs::create_dir_all(directory)}fn open_file(file_path: &Utf8Path) -> io::Result<File> {ensure_directory(file_path.parent().unwrap())?;File::options().create(true).read(true).write(true).open(file_path)}fn update_file(path: &Utf8Path, buffer: &[u8]) -> io::Result<()> {let mut file = open_file(path)?;let size =usize::try_from(file.metadata()?.len()).expect("file should be smaller than usize::MAX");if buffer.len() == size {let mut current_contents = Vec::with_capacity(size);file.read_to_end(&mut current_contents)?;if current_contents == buffer {tracing::debug!(%path, "skipping write of unchanged file");return Ok(());}}// File changed in the import processfile.write_all(buffer)?;file.set_len(u64::try_from(buffer.len()).expect("should always work"))}