core: debugutils: Write dot files atomically

Replace fopen/fputs with g_file_set_contents() to ensure dot files are written
atomically. This prevents tools like gst-dots-viewer from reading partially
written files when watching the dot folder.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7999>
This commit is contained in:
Thibault Saunier 2025-01-09 20:23:08 -03:00 committed by GStreamer Marge Bot
parent b41d5c733d
commit 4b74819671

View File

@ -854,7 +854,6 @@ gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details,
const gchar * file_name)
{
gchar *full_file_name = NULL;
FILE *out;
g_return_if_fail (GST_IS_BIN (bin));
@ -870,20 +869,17 @@ gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details,
full_file_name = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.dot",
priv_gst_dump_dot_dir, file_name);
if ((out = fopen (full_file_name, "wb"))) {
gchar *buf;
GError *err = NULL;
gchar *buf;
buf = gst_debug_bin_to_dot_data (bin, details);
fputs (buf, out);
buf = gst_debug_bin_to_dot_data (bin, details);
if (!g_file_set_contents (full_file_name, buf, -1, &err)) {
GST_WARNING ("Failed to write file '%s' for writing: %s", full_file_name,
err->message);
g_free (buf);
fclose (out);
GST_INFO ("wrote bin graph to : '%s'", full_file_name);
} else {
GST_WARNING ("Failed to open file '%s' for writing: %s", full_file_name,
g_strerror (errno));
}
g_clear_error (&err);
g_free (buf);
g_free (full_file_name);
}