Changes to cache location

This commit is contained in:
Mateusz Słodkowicz 2024-03-20 12:55:10 +01:00
parent 0447e9edd2
commit 3a831a5194
Signed by: materus
GPG Key ID: 28D140BCA60B4FD1
2 changed files with 14 additions and 5 deletions

View File

@ -1,5 +1,7 @@
FROM rust:1.76.0
ENV CURRENCY_CACHE="/tmp/docker_currency_cache.db"
WORKDIR /usr/src/currency-exchange
COPY . .

View File

@ -1,6 +1,6 @@
use std::{
env::{temp_dir, var_os},
path::PathBuf
path::PathBuf,
};
pub const CACHE_LOCATION_ENV_NAME: &str = "CURRENCY_CACHE";
@ -18,12 +18,19 @@ pub fn get_endpoint() -> String {
}
pub fn get_cache_path() -> PathBuf {
let mut path: PathBuf = PathBuf::new();
match var_os(CACHE_LOCATION_ENV_NAME) {
Some(val) => path.push(val),
None => {
path.push(temp_dir());
path.push("currencyCache.db");
}
None => match var_os("XDG_CACHE_HOME") {
Some(val) => {
path.push(val);
path.push("currencyCache.db");
}
None => {
path.push(temp_dir());
path.push("currencyCache.db");
}
},
}
path