Skip to content

Commit

Permalink
Merge pull request #163 from viceice/fix/win-local-appdata
Browse files Browse the repository at this point in the history
fix: use `LOCALAPPDATA` env on windows
  • Loading branch information
stepchowfun authored Jul 14, 2021
2 parents d62d909 + 09e077f commit db5097d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "docuum"
version = "0.19.1"
version = "0.19.2"
authors = ["Stephan Boyer <[email protected]>"]
edition = "2018"
description = "LRU eviction of Docker images."
Expand Down
10 changes: 9 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -32,7 +33,14 @@ pub struct State {
// Where the program state is persisted on disk
fn path() -> Option<PathBuf> {
// [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.
Expand Down

0 comments on commit db5097d

Please sign in to comment.