2004-03-20 Colin Walters <walters@verbum.org>
+ * gst/registries/gstxmlregistry.c:
+ (gst_xml_registry_open_func, gst_xml_registry_close_func): Make
+ registry saving atomic.
+
+2004-03-20 Colin Walters <walters@verbum.org>
+
* gst/registries/gstxmlregistry.c (gst_xml_registry_get_perms_func): Just use
access() instead of actually creating and deleting files.
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
+#include <fcntl.h>
#include <utime.h>
#include <gst/gst_private.h>
registry->location);
registry->regfile = fopen (registry->location, "r");
} else if (mode == GST_XML_REGISTRY_WRITE) {
+ char *tmploc;
+ int fd;
+
g_return_val_if_fail (gst_registry->flags & GST_REGISTRY_WRITABLE, FALSE);
- GST_CAT_DEBUG (GST_CAT_GST_INIT, "opening registry %s for writing",
- registry->location);
- registry->regfile = fopen (registry->location, "w");
+ tmploc = g_strconcat (registry->location, ".tmp", NULL);
+
+ GST_CAT_DEBUG (GST_CAT_GST_INIT, "opening registry %s for writing", tmploc);
+
+ if ((fd = open (tmploc, O_WRONLY | O_CREAT | O_EXCL, 0644)) < 0) {
+ g_free (tmploc);
+ return FALSE;
+ }
+ g_free (tmploc);
+
+ registry->regfile = fdopen (fd, "w");
}
if (!registry->regfile)
static gboolean
gst_xml_registry_close_func (GstXMLRegistry * registry)
{
+ char *tmploc;
+
GST_CAT_DEBUG (GST_CAT_GST_INIT, "closing registry %s", registry->location);
fclose (registry->regfile);
+ /* If we opened for writing, rename our temporary file. */
+ tmploc = g_strconcat (registry->location, ".tmp", NULL);
+ if (g_file_test (tmploc, G_FILE_TEST_EXISTS))
+ rename (tmploc, registry->location);
+ g_free (tmploc);
+
registry->open = FALSE;
return TRUE;