From af249dbce165e3c27cf65c7a6b41deeb9086e949 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 5 Jun 2024 21:03:14 +0200 Subject: [PATCH] Write shebang recipes to $XDG_RUNTIME_DIR (#2128) --- src/error.rs | 8 ++++---- src/recipe.rs | 6 +++--- tests/tempdir.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/error.rs b/src/error.rs index 06b0edf..63785d4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -20,7 +20,7 @@ pub(crate) enum Error<'src> { token: Token<'src>, output_error: OutputError, }, - CacheDirIo { + RuntimeDirIo { io_error: io::Error, path: PathBuf, }, @@ -287,9 +287,6 @@ impl<'src> ColorDisplay for Error<'src> { }?, OutputError::Utf8(utf8_error) => write!(f, "Backtick succeeded but stdout was not utf8: {utf8_error}")?, } - CacheDirIo { io_error, path } => { - write!(f, "I/O error in cache dir `{}`: {io_error}", path.display())?; - } ChooserInvoke { shell_binary, shell_arguments, chooser, io_error} => { let chooser = chooser.to_string_lossy(); write!(f, "Chooser `{shell_binary} {shell_arguments} {chooser}` invocation failed: {io_error}")?; @@ -407,6 +404,9 @@ impl<'src> ColorDisplay for Error<'src> { write!(f, "Recipe `{recipe}` was not confirmed")?; } RegexCompile { source } => write!(f, "{source}")?, + RuntimeDirIo { io_error, path } => { + write!(f, "I/O error in runtime dir `{}`: {io_error}", path.display())?; + } Search { search_error } => Display::fmt(search_error, f)?, Shebang { recipe, command, argument, io_error} => { if let Some(argument) = argument { diff --git a/src/recipe.rs b/src/recipe.rs index 97dc847..4d17103 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -353,9 +353,9 @@ impl<'src, D> Recipe<'src, D> { let tempdir = match &context.settings.tempdir { Some(tempdir) => tempdir_builder.tempdir_in(context.search.working_directory.join(tempdir)), None => { - if let Some(cache_dir) = dirs::cache_dir() { - let path = cache_dir.join("just"); - fs::create_dir_all(&path).map_err(|io_error| Error::CacheDirIo { + if let Some(runtime_dir) = dirs::runtime_dir() { + let path = runtime_dir.join("just"); + fs::create_dir_all(&path).map_err(|io_error| Error::RuntimeDirIo { io_error, path: path.clone(), })?; diff --git a/tests/tempdir.rs b/tests/tempdir.rs index a7d2a5f..4f89792 100644 --- a/tests/tempdir.rs +++ b/tests/tempdir.rs @@ -5,8 +5,8 @@ pub(crate) fn tempdir() -> TempDir { builder.prefix("just-test-tempdir"); - if let Some(cache_dir) = dirs::cache_dir() { - let path = cache_dir.join("just"); + if let Some(runtime_dir) = dirs::runtime_dir() { + let path = runtime_dir.join("just"); fs::create_dir_all(&path).unwrap(); builder.tempdir_in(path) } else {