Skip to content

Commit

Permalink
re-download improve
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Jan 27, 2024
1 parent bd59d00 commit a0e8431
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
.env
.env
result
4 changes: 2 additions & 2 deletions src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Migrator {
let name = demo.url.rsplit('/').next().unwrap();

let stored_hash = self.store.hash(name)?;
if stored_hash != demo.hash {
if stored_hash != Some(demo.hash) {
warn!(
stored_hash = debug(stored_hash),
expected_hash = debug(demo.hash),
Expand All @@ -81,7 +81,7 @@ impl Migrator {
&self.backend,
self.store.generate_path(name).to_str().unwrap(),
&self.store.generate_url(name),
stored_hash,
demo.hash,
&self.key,
)
.await?;
Expand Down
14 changes: 11 additions & 3 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ impl Store {
}

pub fn remove(&self, name: &str) -> std::io::Result<()> {
fs::remove_file(self.generate_path(name))
let path = self.generate_path(name);
if path.exists() {
fs::remove_file(path)
} else {
Ok(())
}
}

pub fn hash(&self, name: &str) -> Result<[u8; 16], Error> {
pub fn hash(&self, name: &str) -> Result<Option<[u8; 16]>, Error> {
let path = self.generate_path(name);
if !path.exists() {
return Ok(None);
}
let mut file = File::open(path)?;

let mut hash = Context::new();
Expand All @@ -53,7 +61,7 @@ impl Store {
hash.consume(data);
}

Ok(hash.compute().0)
Ok(Some(hash.compute().0))
}

pub fn generate_path(&self, name: &str) -> PathBuf {
Expand Down

0 comments on commit a0e8431

Please sign in to comment.