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:
1 parent
6584b2f92f
commit
2e463dab3a
6 files changed
+71
-8
No files matched your search
@@ -19,14 +19,35 @@ use std::path::PathBuf;
|
||||
/// Default configuration file name.
|
||||
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.
|
||||
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")
|
||||
.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.
|
||||
pub fn get_default_output_dir() -> Option<PathBuf> {
|
||||
directories::ProjectDirs::from("com", "leaguerecorder", "record-daemon")
|
||||
.map(|dirs| dirs.data_dir().join("recordings"))
|
||||
get_data_dir().map(|dir| dir.join("recordings"))
|
||||
}
|
||||
@@ -13,17 +13,32 @@ pub use server::{IpcServer, IpcServerConfig};
|
||||
|
||||
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.
|
||||
#[cfg(target_os = "linux")]
|
||||
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")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|_| PathBuf::from("/tmp"))
|
||||
.join("record-daemon.sock")
|
||||
.join(name)
|
||||
}
|
||||
|
||||
/// Default socket path for the IPC server.
|
||||
#[cfg(target_os = "windows")]
|
||||
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")
|
||||
}
|
||||
@@ -712,7 +712,14 @@ async fn main() -> Result<()> {
|
||||
} else {
|
||||
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);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user