Changes to cache location
This commit is contained in:
parent
0447e9edd2
commit
3a831a5194
|
@ -1,5 +1,7 @@
|
||||||
FROM rust:1.76.0
|
FROM rust:1.76.0
|
||||||
|
|
||||||
|
ENV CURRENCY_CACHE="/tmp/docker_currency_cache.db"
|
||||||
|
|
||||||
WORKDIR /usr/src/currency-exchange
|
WORKDIR /usr/src/currency-exchange
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{
|
use std::{
|
||||||
env::{temp_dir, var_os},
|
env::{temp_dir, var_os},
|
||||||
path::PathBuf
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const CACHE_LOCATION_ENV_NAME: &str = "CURRENCY_CACHE";
|
pub const CACHE_LOCATION_ENV_NAME: &str = "CURRENCY_CACHE";
|
||||||
|
@ -18,12 +18,19 @@ pub fn get_endpoint() -> String {
|
||||||
}
|
}
|
||||||
pub fn get_cache_path() -> PathBuf {
|
pub fn get_cache_path() -> PathBuf {
|
||||||
let mut path: PathBuf = PathBuf::new();
|
let mut path: PathBuf = PathBuf::new();
|
||||||
|
|
||||||
match var_os(CACHE_LOCATION_ENV_NAME) {
|
match var_os(CACHE_LOCATION_ENV_NAME) {
|
||||||
Some(val) => path.push(val),
|
Some(val) => path.push(val),
|
||||||
|
None => match var_os("XDG_CACHE_HOME") {
|
||||||
|
Some(val) => {
|
||||||
|
path.push(val);
|
||||||
|
path.push("currencyCache.db");
|
||||||
|
}
|
||||||
None => {
|
None => {
|
||||||
path.push(temp_dir());
|
path.push(temp_dir());
|
||||||
path.push("currencyCache.db");
|
path.push("currencyCache.db");
|
||||||
}
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
path
|
path
|
||||||
|
|
Reference in New Issue