From d7fa1464ffd3fc0dc4cabb1442f27be2d5adf17c Mon Sep 17 00:00:00 2001 From: awiouy Date: Sat, 10 Feb 2018 11:26:26 +0100 Subject: [PATCH] core API: move mkdir_existing to cache.rs --- core/src/cache.rs | 19 ++++++++++++++++--- core/src/util/mod.rs | 13 ------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/core/src/cache.rs b/core/src/cache.rs index 28b787ff..1a58bdc0 100644 --- a/core/src/cache.rs +++ b/core/src/cache.rs @@ -1,8 +1,11 @@ -use std::path::PathBuf; -use std::io::Read; +use std::fs; use std::fs::File; +use std::io; +use std::io::Read; +use std::path::Path; +use std::path::PathBuf; -use util::{FileId, mkdir_existing}; +use util::FileId; use authentication::Credentials; #[derive(Clone)] @@ -11,6 +14,16 @@ pub struct Cache { use_audio_cache: bool, } +fn mkdir_existing(path: &Path) -> io::Result<()> { + fs::create_dir(path).or_else(|err| { + if err.kind() == io::ErrorKind::AlreadyExists { + Ok(()) + } else { + Err(err) + } + }) +} + impl Cache { pub fn new(location: PathBuf, use_audio_cache: bool) -> Cache { mkdir_existing(&location).unwrap(); diff --git a/core/src/util/mod.rs b/core/src/util/mod.rs index f9304f0b..f96a5431 100644 --- a/core/src/util/mod.rs +++ b/core/src/util/mod.rs @@ -2,11 +2,8 @@ use num_bigint::BigUint; use num_traits::{Zero, One}; use num_integer::Integer; use rand::{Rng, Rand}; -use std::io; use std::mem; use std::ops::{Mul, Rem, Shr}; -use std::fs; -use std::path::Path; use std::process::Command; mod int128; @@ -21,16 +18,6 @@ pub fn rand_vec(rng: &mut G, size: usize) -> Vec { rng.gen_iter().take(size).collect() } -pub fn mkdir_existing(path: &Path) -> io::Result<()> { - fs::create_dir(path).or_else(|err| { - if err.kind() == io::ErrorKind::AlreadyExists { - Ok(()) - } else { - Err(err) - } - }) -} - pub fn run_program(program: &str) { info!("Running {}", program); let mut v: Vec<&str> = program.split_whitespace().collect();