From 834dd48444654c605b9c21bf0864b239b3d8ddb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= Date: Sun, 27 Aug 2017 17:54:00 +0200 Subject: [PATCH] Don't download media files if exist --- src/util.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util.rs b/src/util.rs index 063ff0aa..d0c04e4d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -14,6 +14,7 @@ use self::serde_json::Value as JsonValue; use std::collections::HashMap; use self::url::Url; use std::io::Read; +use std::path::Path; use std::fs::File; use std::io::prelude::*; @@ -214,6 +215,12 @@ pub fn dw_media(base: &Url, url: &str, thumb: bool, dest: Option<&str>, w: i32, Some(d) => String::from(d) + &media }; + let pathname = fname.clone(); + let p = Path::new(&pathname); + if p.is_file() { + return Ok(fname); + } + let mut file = File::create(&fname)?; let buffer = get_media(url.as_str())?; file.write_all(&buffer)?;