mirror of
https://github.com/numtide/treefmt.git
synced 2024-08-17 04:40:27 +03:00
lazily create the cache directory (#174)
Don't touch $HOME unless needed. Fixes #173.
This commit is contained in:
parent
db604fd694
commit
3aee5bd5d3
17
default.nix
17
default.nix
@ -75,4 +75,21 @@ in
|
||||
|
||||
# Flake attributes
|
||||
default = treefmt;
|
||||
|
||||
# Test that no HOME is needed when --no-cache is passed
|
||||
treefmt-no-cache-no-home = nixpkgs.runCommandLocal "format"
|
||||
{
|
||||
buildInputs = [ treefmt ];
|
||||
}
|
||||
''
|
||||
cat <<CONFIG > treefmt.toml
|
||||
[formatter.nix]
|
||||
command = "${nixpkgs.nixpkgs-fmt}/bin/nixpkgs-fmt"
|
||||
includes = ["*.nix"]
|
||||
CONFIG
|
||||
# uncommenting this makes it work fine
|
||||
# export HOME=$TMP
|
||||
treefmt --no-cache --fail-on-change -C ./.
|
||||
touch $out
|
||||
'';
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ use crate::engine::run_treefmt;
|
||||
use anyhow::anyhow;
|
||||
use directories::ProjectDirs;
|
||||
use log::debug;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn format_cmd(
|
||||
@ -38,8 +37,6 @@ pub fn format_cmd(
|
||||
};
|
||||
|
||||
let cache_dir = proj_dirs.cache_dir().join("eval-cache");
|
||||
// Make sure the cache directory exists.
|
||||
fs::create_dir_all(&cache_dir)?;
|
||||
|
||||
debug!(
|
||||
"tree_root={} work_dir={} cache_dir={} config_file={} paths={:?}",
|
||||
|
@ -4,7 +4,6 @@ use crate::expand_path;
|
||||
use anyhow::anyhow;
|
||||
use directories::ProjectDirs;
|
||||
use log::debug;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn format_stdin_cmd(
|
||||
@ -55,8 +54,6 @@ pub fn format_stdin_cmd(
|
||||
let path = expand_path(paths.first().unwrap(), work_dir);
|
||||
|
||||
let cache_dir = proj_dirs.cache_dir().join("eval-cache");
|
||||
// Make sure the cache directory exists.
|
||||
fs::create_dir_all(&cache_dir)?;
|
||||
|
||||
debug!(
|
||||
"tree_root={} work_dir={} cache_dir={} config_file={} path={}",
|
||||
|
@ -9,7 +9,7 @@ use log::{debug, error, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha1::{Digest, Sha1};
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs::{read_to_string, File};
|
||||
use std::fs::{create_dir_all, read_to_string, File};
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@ -78,6 +78,9 @@ impl CacheManifest {
|
||||
pub fn try_write(self, cache_dir: &Path, treefmt_toml: &Path) -> Result<()> {
|
||||
let manifest_path = get_manifest_path(cache_dir, treefmt_toml);
|
||||
debug!("cache: writing to {}", manifest_path.display());
|
||||
// Make sure the cache directory exists.
|
||||
create_dir_all(manifest_path.parent().unwrap())?;
|
||||
// Then write the file.
|
||||
let mut f = File::create(manifest_path)?;
|
||||
f.write_all(
|
||||
format!(
|
||||
|
Loading…
Reference in New Issue
Block a user