From 2ad0539a82c34793d3acac603ec5f23699f0ddc6 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Thu, 21 Dec 2017 22:15:17 +0200 Subject: [PATCH] Downloader: Overwrite episode.lenght column upon download finish with the actual file size. Closes #22. --- hammond-downloader/src/downloader.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index eb0fd2f..d0505fd 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -6,6 +6,7 @@ use mime_guess; use std::fs::{rename, DirBuilder, File}; use std::io::{BufWriter, Read, Write}; use std::path::Path; +use std::fs; use errors::*; use hammond_data::{EpisodeWidgetQuery, PodcastCoverQuery}; @@ -123,6 +124,11 @@ pub fn get_episode(ep: &mut EpisodeWidgetQuery, download_folder: &str) -> Result if let Ok(path) = res { // If download succedes set episode local_uri to dlpath. ep.set_local_uri(Some(&path)); + + let size = fs::metadata(path); + if let Ok(s) = size { + ep.set_length(Some(s.len() as i32)) + }; ep.save()?; Ok(()) } else {