pipeline-snapshot: Use user_cache_dir from the GLib

The 'dirs' crate doesn't behave the same leading to incompatibility

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1956>
This commit is contained in:
Thibault Saunier 2025-02-11 22:45:11 -03:00
parent 2a11f0b577
commit 50472dc22c
3 changed files with 26 additions and 63 deletions

49
Cargo.lock generated
View file

@ -1657,27 +1657,6 @@ dependencies = [
"subtle",
]
[[package]]
name = "dirs"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.59.0",
]
[[package]]
name = "displaydoc"
version = "0.2.5"
@ -3236,7 +3215,6 @@ dependencies = [
"async-tungstenite",
"atomic_refcell",
"chrono",
"dirs",
"etherparse",
"futures",
"gst-plugin-version-helper",
@ -4781,16 +4759,6 @@ version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.8.0",
"libc",
]
[[package]]
name = "librespot-audio"
version = "0.6.0"
@ -5492,12 +5460,6 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "option-operations"
version = "0.5.0"
@ -6314,17 +6276,6 @@ dependencies = [
"bitflags 2.8.0",
]
[[package]]
name = "redox_users"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b"
dependencies = [
"getrandom 0.2.15",
"libredox",
"thiserror 2.0.11",
]
[[package]]
name = "regex"
version = "1.11.1"

View file

@ -15,7 +15,6 @@ regex = "1"
atomic_refcell = "0.1"
pcap-file = "1.1.1"
etherparse = "0.16.0"
dirs = "6"
chrono = "0.4.35"
walkdir = "2"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

View file

@ -71,7 +71,7 @@
use futures::prelude::*;
use std::collections::HashMap;
use std::io::Write;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::{Arc, Mutex, RwLock};
use tokio::runtime;
@ -230,7 +230,7 @@ impl Settings {
fn set_xdg_cache(&mut self, xdg_cache: bool) {
self.xdg_cache = xdg_cache;
if xdg_cache {
let mut path = dirs::cache_dir().expect("Failed to find cache directory");
let mut path = gst::glib::user_cache_dir();
path.push("gstreamer-dots");
self.dot_dir = path.to_str().map(|s| s.to_string());
}
@ -630,21 +630,34 @@ impl PipelineSnapshot {
settings.dot_prefix.as_ref().map_or("", |s| s.as_str()),
pipeline.name(),
);
gst::debug!(CAT, imp = self, "Writing {}", dot_path);
match std::fs::File::create(&dot_path) {
Ok(mut f) => {
let data = pipeline.debug_to_dot_data(gst::DebugGraphDetails::all());
if let Err(e) = f.write_all(data.as_bytes()) {
gst::warning!(CAT, imp = self, "Failed to write {}: {}", dot_path, e);
}
}
Err(e) => {
gst::warning!(CAT, imp = self, "Failed to create {}: {}", dot_path, e);
}
let data = pipeline.debug_to_dot_data(gst::DebugGraphDetails::all());
if let Err(e) = self.write_dot_file_atomically(Path::new(&dot_path), data.as_bytes()) {
gst::warning!(CAT, imp = self, "Failed to write {}: {}", dot_path, e);
}
}
}
fn write_dot_file_atomically(&self, path: &Path, data: &[u8]) -> std::io::Result<()> {
// Create a temporary file in the same directory
let tmp_path = path.with_extension("dot.tmp");
// Write data to temporary file
{
let mut tmp_file = std::fs::File::create(&tmp_path)?;
tmp_file.write_all(data)?;
// Ensure all data is written to disk
tmp_file.sync_all()?;
}
// Atomically rename temporary file to target path
std::fs::rename(tmp_path, path)?;
Ok(())
}
#[cfg(unix)]
fn setup_signal(&self) -> anyhow::Result<()> {
use signal_hook::consts::signal::*;