diff --git a/src/data/import/download.rs b/src/data/import/download.rs index 2285b99..0c748d9 100644 --- a/src/data/import/download.rs +++ b/src/data/import/download.rs @@ -1,4 +1,4 @@ -use std::fs::{remove_dir_all, File}; +use std::fs::remove_dir_all; use anyhow::{Context as _, Error}; use camino::{Utf8Path, Utf8PathBuf}; @@ -44,8 +44,15 @@ impl Import for Download { let mut skip_download = false; if tagfile.exists() { - // TODO: check if tagfile was created with same info - skip_download = true; + let tagfile_contents = std::fs::read_to_string(tagfile.as_path())?; + let tagfile_source = + bincode::deserialize_from::<_, Source>(tagfile_contents.as_bytes()); + + if let Ok(tagfile_source) = tagfile_source { + if tagfile_source == self.source { + skip_download = true; + } + } } if !skip_download { if target_path.exists() { @@ -61,7 +68,7 @@ impl Import for Download { format!("cloning git url: \"{url}\" commit: \"{commit}\"") })?; - File::create(tagfile)?; + self.create_tagfile(tagfile)?; } Source::Git(Git::Branch { url, @@ -77,7 +84,7 @@ impl Import for Download { format!("cloning git url: \"{url}\" branch/tag: \"{branch_or_tag}\"") })?; - File::create(tagfile)?; + self.create_tagfile(tagfile)?; } Source::Git(Git::Default { url }) => { println!("IMPORT Git {url} -> {target_path}"); @@ -86,7 +93,7 @@ impl Import for Download { .do_clone() .with_context(|| format!("cloning git url: \"{url}\""))?; - File::create(tagfile)?; + self.create_tagfile(tagfile)?; } Source::Laze(name) => { let mut at_least_one = false; @@ -108,7 +115,8 @@ impl Import for Download { .with_context(|| format!("creating {filename}"))?; } if at_least_one { - File::create(&tagfile).with_context(|| format!("creating {tagfile}"))?; + self.create_tagfile(&tagfile) + .with_context(|| format!("creating {tagfile}"))?; } else { return Err(anyhow!("could not import from laze defaults: {name}")); } diff --git a/src/download.rs b/src/download.rs index 10af45c..c4443e6 100644 --- a/src/download.rs +++ b/src/download.rs @@ -1,6 +1,6 @@ //! This module deals with "download:" directives -use std::borrow::Cow; +use std::{borrow::Cow, path::Path}; use anyhow::Result; use im::HashMap; @@ -72,6 +72,13 @@ impl Download { } } + pub fn create_tagfile>(&self, path: P) -> Result<()> { + let path = path.as_ref(); + let contents = bincode::serialize(&self.source)?; + std::fs::write(path, contents)?; + Ok(()) + } + fn render( &self, module: &Module,