diff --git a/CHANGELOG.md b/CHANGELOG.md index 75a9a1f..db4b1ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.19.2] - 2021-07-14 + +### Fixed +- Use `LOCALAPPDATA` on windows when `dirs::data_local_dir()` is `None` which happens on `mcr.microsoft.com/windows/nanoserver` Docker image. + ## [0.19.1] - 2021-07-14 ### Fixed diff --git a/Cargo.lock b/Cargo.lock index 44e6bdc..ea94e4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -120,7 +120,7 @@ dependencies = [ [[package]] name = "docuum" -version = "0.19.1" +version = "0.19.2" dependencies = [ "atty", "byte-unit", diff --git a/Cargo.toml b/Cargo.toml index 7f5f8fd..3e85cbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "docuum" -version = "0.19.1" +version = "0.19.2" authors = ["Stephan Boyer "] edition = "2018" description = "LRU eviction of Docker images." diff --git a/src/state.rs b/src/state.rs index ad9ae8c..ba75fc6 100644 --- a/src/state.rs +++ b/src/state.rs @@ -2,6 +2,7 @@ use crate::format::CodeStr; use serde::{Deserialize, Serialize}; use std::{ collections::HashMap, + env, fs::{create_dir_all, read_to_string}, io::{self, Write}, path::PathBuf, @@ -32,7 +33,14 @@ pub struct State { // Where the program state is persisted on disk fn path() -> Option { // [tag:state_path_has_parent] - dirs::data_local_dir().map(|path| path.join("docuum/state.yml")) + dirs::data_local_dir() + .or_else(|| { + // In the `mcr.microsoft.com/windows/nanoserver` Docker image, `dirs::data_local_dir()` + // returns `None` (see https://github.com/dirs-dev/dirs-rs/issues/34 for details). So + // we fall back to the value of the `LOCALAPPDATA` environment variable in that case. + env::var("LOCALAPPDATA").ok().map(Into::into) + }) + .map(|path| path.join("docuum/state.yml")) } // Return the state in which the program starts, if no state was loaded from disk.