record-daemon: give scripted runs a home of their own

An end-to-end run of mine put its settings through updateSettings, which
wrote them to the user's real config: output path in %TEMP%, a "probe"
application, 30 fps. The next game recorded into %TEMP%, so it showed up
in the history with its metadata and no video beside it.

RECORD_DAEMON_HOME now moves the config directory, the recordings, the
logs and the IPC pipe under one directory. The app reads the same
variable, so a probe talks to the scratch daemon instead of the real one.
Default paths are unchanged.

The daemon also logs its config and recordings paths at startup, which is
the first thing to look at when a recording has no video.
This commit is contained in:
vhaudiquet committed 2026-11-17 00:19:13 +01:00
1 parent 6584b2f92f
commit 2e463dab3a
6 files changed
+71 -8

No files matched your search

+6
View File
@@ -8,8 +8,14 @@ use std::time::Duration;
use crate::ipc::Client; use crate::ipc::Client;
/// Set this to point the app and the daemon at a scratch directory, as scripts do.
pub const HOME_ENV: &str = "RECORD_DAEMON_HOME";
/// The daemon's data directory, shared with the daemon itself. /// The daemon's data directory, shared with the daemon itself.
pub fn data_dir() -> Option<PathBuf> { pub fn data_dir() -> Option<PathBuf> {
if let Some(home) = std::env::var_os(HOME_ENV).filter(|value| !value.is_empty()) {
return Some(PathBuf::from(home).join("data"));
}
directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon") directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon")
.map(|dirs| dirs.data_dir().to_path_buf()) .map(|dirs| dirs.data_dir().to_path_buf())
} }
+11 -2
View File
@@ -69,16 +69,25 @@ pub struct IpcResponse {
pub error: Option<String>, pub error: Option<String>,
} }
/// The pipe the daemon listens on. /// The pipe the daemon listens on. A scratch home, as scripts set, gets a pipe of its own.
pub fn default_socket_path() -> PathBuf { pub fn default_socket_path() -> PathBuf {
let scratch = std::env::var_os(crate::daemon::HOME_ENV).is_some_and(|value| !value.is_empty());
#[cfg(windows)] #[cfg(windows)]
{ {
if scratch {
return PathBuf::from(r"\\.\pipe\record-daemon-scratch");
}
PathBuf::from(r"\\.\pipe\record-daemon") PathBuf::from(r"\\.\pipe\record-daemon")
} }
#[cfg(not(windows))] #[cfg(not(windows))]
{ {
let name = if scratch {
"record-daemon-scratch.sock"
} else {
"record-daemon.sock"
};
let dir = std::env::var("XDG_RUNTIME_DIR").unwrap_or_else(|_| "/tmp".into()); let dir = std::env::var("XDG_RUNTIME_DIR").unwrap_or_else(|_| "/tmp".into());
Path::new(&dir).join("record-daemon.sock") Path::new(&dir).join(name)
} }
} }
+7 -2
View File
@@ -109,8 +109,13 @@ cargo build --release
## Configuration ## Configuration
The configuration file is stored at: The configuration file is stored at:
- Linux: `~/.config/record-daemon/config.toml` - Linux: `~/.config/leaguerecorder/record-daemon/config.toml`
- Windows: `%APPDATA%\record-daemon\config.toml` - Windows: `%APPDATA%\leaguerecorder\record-daemon\config\config.toml`
Recordings and timelines go to `recordings` next to that `config` folder.
Set `RECORD_DAEMON_HOME` to move all of it, config, recordings, logs and the IPC pipe, under one
directory. Scripts and end-to-end tests use it so a run never reads or writes the real settings.
### Example Configuration ### Example Configuration
+23 -2
View File
@@ -19,14 +19,35 @@ use std::path::PathBuf;
/// Default configuration file name. /// Default configuration file name.
pub const CONFIG_FILE_NAME: &str = "config.toml"; pub const CONFIG_FILE_NAME: &str = "config.toml";
/// Set this to run the daemon against a scratch directory instead of the user's config,
/// recordings and log. Scripts and end-to-end tests set it so they cannot touch real data.
pub const HOME_ENV: &str = "RECORD_DAEMON_HOME";
fn override_home() -> Option<PathBuf> {
std::env::var_os(HOME_ENV)
.filter(|value| !value.is_empty())
.map(PathBuf::from)
}
/// Get the default configuration directory. /// Get the default configuration directory.
pub fn get_config_dir() -> Option<PathBuf> { pub fn get_config_dir() -> Option<PathBuf> {
if let Some(home) = override_home() {
return Some(home.join("config"));
}
directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon") directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon")
.map(|dirs| dirs.config_dir().to_path_buf()) .map(|dirs| dirs.config_dir().to_path_buf())
} }
/// Get the data directory, which holds `recordings` and `logs`.
pub fn get_data_dir() -> Option<PathBuf> {
if let Some(home) = override_home() {
return Some(home.join("data"));
}
directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon")
.map(|dirs| dirs.data_dir().to_path_buf())
}
/// Get the default output directory for recordings. /// Get the default output directory for recordings.
pub fn get_default_output_dir() -> Option<PathBuf> { pub fn get_default_output_dir() -> Option<PathBuf> {
directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon") get_data_dir().map(|dir| dir.join("recordings"))
.map(|dirs| dirs.data_dir().join("recordings"))
} }
+16 -1
View File
@@ -13,17 +13,32 @@ pub use server::{IpcServer, IpcServerConfig};
use std::path::PathBuf; use std::path::PathBuf;
/// Whether this run uses a scratch home, which gets a pipe of its own.
fn scratch_home() -> bool {
std::env::var_os(crate::config::HOME_ENV).is_some_and(|value| !value.is_empty())
}
/// Default socket path for the IPC server. /// Default socket path for the IPC server.
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub fn default_socket_path() -> PathBuf { pub fn default_socket_path() -> PathBuf {
let name = if scratch_home() {
"record-daemon-scratch.sock"
} else {
"record-daemon.sock"
};
std::env::var("XDG_RUNTIME_DIR") std::env::var("XDG_RUNTIME_DIR")
.map(PathBuf::from) .map(PathBuf::from)
.unwrap_or_else(|_| PathBuf::from("/tmp")) .unwrap_or_else(|_| PathBuf::from("/tmp"))
.join("record-daemon.sock") .join(name)
} }
/// Default socket path for the IPC server. /// Default socket path for the IPC server.
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
pub fn default_socket_path() -> PathBuf { pub fn default_socket_path() -> PathBuf {
// A scratch home gets its own pipe, so a script cannot take the pipe the installed app
// talks to.
if scratch_home() {
return PathBuf::from(r"\\.\pipe\record-daemon-scratch");
}
PathBuf::from(r"\\.\pipe\record-daemon") PathBuf::from(r"\\.\pipe\record-daemon")
} }
+8 -1
View File
@@ -712,7 +712,14 @@ async fn main() -> Result<()> {
} else { } else {
config::load_config()? config::load_config()?
}; };
// Create and run daemon // Say where the pieces live: the first thing to check when a game records without a video.
info!(
"config: {}, recordings: {}",
config::get_config_dir()
.map(|dir| dir.join(config::CONFIG_FILE_NAME).display().to_string())
.unwrap_or_else(|| "the working directory".to_string()),
settings.output.path.display()
);
let mut daemon = Daemon::new(settings); let mut daemon = Daemon::new(settings);
#[cfg(unix)] #[cfg(unix)]
{ {