From 893a1d7792552211366943715d9b8f12298df6fb Mon Sep 17 00:00:00 2001 From: Andrew Kubera Date: Wed, 19 Dec 2018 19:59:20 -0500 Subject: [PATCH] alice-open-data: Replace deprecated env::home_dir with dirs crate --- alice-open-data/Cargo.toml | 1 + alice-open-data/src/lib.rs | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/alice-open-data/Cargo.toml b/alice-open-data/Cargo.toml index 909163d..e36c8b0 100644 --- a/alice-open-data/Cargo.toml +++ b/alice-open-data/Cargo.toml @@ -14,3 +14,4 @@ license = "MPL-2.0" glob = "^0.2.11" failure = "0.1.1" reqwest = "0.8.5" +dirs = "1.0" diff --git a/alice-open-data/src/lib.rs b/alice-open-data/src/lib.rs index b5421f6..9fc9ea0 100644 --- a/alice-open-data/src/lib.rs +++ b/alice-open-data/src/lib.rs @@ -1,9 +1,9 @@ #[macro_use] extern crate failure; +extern crate dirs; extern crate glob; extern crate reqwest; -use std::env; use std::io::{Read}; use std::path::PathBuf; use std::fs::{DirBuilder, File}; @@ -36,7 +36,7 @@ pub fn download(base_dir: PathBuf, url: Url) -> Result { /// Base path to the local ALICE open data directory pub fn data_dir() -> Result { - let mut dir = env::home_dir().ok_or(format_err!("No home directory"))?; + let mut dir = dirs::home_dir().ok_or(format_err!("No home directory"))?; dir.push("lhc_open_data"); Ok(dir) } @@ -94,7 +94,7 @@ fn download_with_https(uri: Url) -> Result { #[cfg(test)] mod tests { - use std::fs; + use std::{fs, env}; #[test] fn test_get_file_lists() { let runs = [ @@ -121,13 +121,13 @@ mod tests { let uri = super::get_file_list(139038).unwrap()[0].clone(); { // Remobe old stuff: - let mut dir = super::env::temp_dir(); + let mut dir = env::temp_dir(); dir.push("eos"); if dir.exists() { fs::remove_dir_all(dir).unwrap(); } } - let base_dir = super::env::temp_dir(); + let base_dir = env::temp_dir(); // Download if file does not exist assert_eq!(super::download(base_dir.clone(), uri.clone()).unwrap(), 14283265); // Don't download twice