diff options
| author | Nathan Jaremko | 2019-03-02 20:47:52 -0500 |
|---|---|---|
| committer | Nathan Jaremko | 2019-03-02 20:48:12 -0500 |
| commit | bfc821456a1164af45d79875c2793c02042efdd8 (patch) | |
| tree | fd37a5d8ee15edba46c6f70831a91166b91046dd | |
| parent | 394a7d9da0a21dd3453815ee9ecdfd10b1b479cd (diff) | |
| download | podcast-bfc821456a1164af45d79875c2793c02042efdd8.tar.bz2 | |
Improve extension handling
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/actions.rs | 6 | ||||
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/utils.rs | 9 |
4 files changed, 10 insertions, 9 deletions
@@ -1,7 +1,7 @@ [package] name = "podcast" edition = "2018" -version = "0.10.0" +version = "0.10.1" authors = ["Nathan Jaremko <njaremko@gmail.com>"] description = "A command line podcast manager" license = "GPL-3.0" diff --git a/src/actions.rs b/src/actions.rs index c3ed2ac..c943769 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -66,11 +66,9 @@ pub fn update_subscription(sub: &mut Subscription) -> Result<()> { let resp = reqwest::get(&sub.url)?; let podcast = Podcast::from(Channel::read_from(BufReader::new(resp))?); - let mut filename = String::from(podcast.title()); - filename.push_str(".xml"); - let mut podcast_rss_path = get_xml_dir()?; - podcast_rss_path.push(&filename); + podcast_rss_path.push(podcast.title()); + podcast_rss_path.set_extension("xml"); let file = File::create(&podcast_rss_path)?; (*podcast).write_to(BufWriter::new(file))?; diff --git a/src/main.rs b/src/main.rs index bdf913a..640e480 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,7 @@ mod errors { use self::structs::*; use errors::Result; -const VERSION: &str = "0.10.0"; +const VERSION: &str = "0.10.1"; fn main() -> Result<()> { utils::create_directories()?; diff --git a/src/utils.rs b/src/utils.rs index e00df98..bb96909 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -13,8 +13,11 @@ const UNSUBSCRIBE_NOTE: &str = "Note: this does NOT delete any downloaded podcas pub fn trim_extension(filename: &str) -> Option<String> { let name = String::from(filename); - let index = name.rfind('.')?; - Some(String::from(&name[0..index])) + if name.contains(".") { + name.rfind('.').map(|index| String::from(&name[0..index])) + } else { + Some(name) + } } pub fn find_extension(input: &str) -> Option<String> { @@ -166,6 +169,6 @@ mod tests { #[test] fn test_trim_extension_invalid() { - assert_eq!(trim_extension("test"), None) + assert_eq!(trim_extension("test"), Some("test".into())) } } |
