mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
core API: move mkdir_existing to cache.rs
This commit is contained in:
parent
77882836ce
commit
d7fa1464ff
2 changed files with 16 additions and 16 deletions
|
@ -1,8 +1,11 @@
|
||||||
use std::path::PathBuf;
|
use std::fs;
|
||||||
use std::io::Read;
|
|
||||||
use std::fs::File;
|
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;
|
use authentication::Credentials;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -11,6 +14,16 @@ pub struct Cache {
|
||||||
use_audio_cache: bool,
|
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 {
|
impl Cache {
|
||||||
pub fn new(location: PathBuf, use_audio_cache: bool) -> Cache {
|
pub fn new(location: PathBuf, use_audio_cache: bool) -> Cache {
|
||||||
mkdir_existing(&location).unwrap();
|
mkdir_existing(&location).unwrap();
|
||||||
|
|
|
@ -2,11 +2,8 @@ use num_bigint::BigUint;
|
||||||
use num_traits::{Zero, One};
|
use num_traits::{Zero, One};
|
||||||
use num_integer::Integer;
|
use num_integer::Integer;
|
||||||
use rand::{Rng, Rand};
|
use rand::{Rng, Rand};
|
||||||
use std::io;
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::{Mul, Rem, Shr};
|
use std::ops::{Mul, Rem, Shr};
|
||||||
use std::fs;
|
|
||||||
use std::path::Path;
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
mod int128;
|
mod int128;
|
||||||
|
@ -21,16 +18,6 @@ pub fn rand_vec<G: Rng, R: Rand>(rng: &mut G, size: usize) -> Vec<R> {
|
||||||
rng.gen_iter().take(size).collect()
|
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) {
|
pub fn run_program(program: &str) {
|
||||||
info!("Running {}", program);
|
info!("Running {}", program);
|
||||||
let mut v: Vec<&str> = program.split_whitespace().collect();
|
let mut v: Vec<&str> = program.split_whitespace().collect();
|
||||||
|
|
Loading…
Reference in a new issue