record-daemon: keep a changed recordings folder usable
A folder typed into the settings screen was saved but never made. OBS does not create directories, so the next recording failed at its output and no timeline reached history. The daemon now makes the folder when settings are saved and again before each recording starts, rejects a folder it cannot use, and resolves it to an absolute path so both programs name the same place. Timelines now store the absolute path of their video next to the file name, so a clip stays reachable after the recording folder changes.
This commit is contained in:
1 parent
f3e44a2132
commit
86fc7cea2f
7 files changed
+82
-5
No files matched your search
@@ -14,7 +14,7 @@ pub use presets::{
|
||||
};
|
||||
pub use settings::{OutputSettings, Settings, VideoSettings};
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Default configuration file name.
|
||||
pub const CONFIG_FILE_NAME: &str = "config.toml";
|
||||
@@ -51,3 +51,37 @@ pub fn get_data_dir() -> Option<PathBuf> {
|
||||
pub fn get_default_output_dir() -> Option<PathBuf> {
|
||||
get_data_dir().map(|dir| dir.join("recordings"))
|
||||
}
|
||||
|
||||
/// Resolve the recordings folder and make it, returning the absolute path.
|
||||
///
|
||||
/// The app and the daemon can run from different working directories, so a relative path
|
||||
/// would name two different folders. The daemon resolves it once and keeps the result, so
|
||||
/// both ends look in the same place.
|
||||
pub fn prepare_output_dir(path: &Path) -> std::io::Result<PathBuf> {
|
||||
let path = if path.as_os_str().is_empty() {
|
||||
get_default_output_dir().unwrap_or_else(|| PathBuf::from("./recordings"))
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
};
|
||||
let path = std::path::absolute(path)?;
|
||||
std::fs::create_dir_all(&path)?;
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn preparing_a_folder_makes_it_absolute_and_creates_it() {
|
||||
let dir = std::env::temp_dir().join(format!("record-daemon-{}", uuid::Uuid::new_v4()));
|
||||
let nested = dir.join("nested");
|
||||
let path = prepare_output_dir(&nested).unwrap();
|
||||
|
||||
assert!(path.is_absolute());
|
||||
assert!(path.is_dir());
|
||||
assert!(path.ends_with("nested"));
|
||||
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user