Index: gstgiosink.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/gio/gstgiosink.c,v
retrieving revision 1.11
diff -u -r1.11 gstgiosink.c
--- gstgiosink.c	20 Apr 2008 10:11:54 -0000	1.11
+++ gstgiosink.c	23 Apr 2008 23:08:07 -0000
@@ -85,7 +85,8 @@
 {
   ARG_0,
   ARG_LOCATION,
-  ARG_FILE
+  ARG_FILE,
+  ARG_OVERWRITE
 };
 
 GST_BOILERPLATE_FULL (GstGioSink, gst_gio_sink, GstGioBaseSink,
@@ -142,6 +143,17 @@
       g_param_spec_object ("file", "File", "GFile to write to",
           G_TYPE_FILE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  /**
+   * GstGioSink:overwrite
+   *
+   * Whether to overwrite any existing file.
+   * 
+   * Since: 0.10.20
+   **/
+  g_object_class_install_property (gobject_class, ARG_OVERWRITE,
+      g_param_spec_boolean ("overwrite", "Overwrite", "Whether to overwrite any existing file",
+          FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_gio_sink_start);
 }
 
@@ -214,6 +226,11 @@
 
       GST_OBJECT_UNLOCK (GST_OBJECT (sink));
       break;
+    case ARG_OVERWRITE:
+      GST_OBJECT_LOCK (GST_OBJECT (sink));
+      sink->overwrite = g_value_get_boolean (value);
+      GST_OBJECT_UNLOCK (GST_OBJECT (sink));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -246,6 +263,11 @@
       g_value_set_object (value, sink->file);
       GST_OBJECT_UNLOCK (GST_OBJECT (sink));
       break;
+    case ARG_OVERWRITE:
+      GST_OBJECT_LOCK (GST_OBJECT (sink));
+      g_value_set_boolean (value, sink->overwrite);
+      GST_OBJECT_UNLOCK (GST_OBJECT (sink));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -261,6 +283,7 @@
   gboolean success;
   GError *err = NULL;
   gchar *uri;
+  const gchar *function_name;
 
   if (sink->file == NULL) {
     GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL),
@@ -272,22 +295,27 @@
   if (!uri)
     uri = g_strdup ("(null)");
 
-  stream =
-      G_OUTPUT_STREAM (g_file_create (sink->file, G_FILE_CREATE_NONE, cancel,
-          &err));
+  if (sink->overwrite) {
+    stream =
+        G_OUTPUT_STREAM (g_file_replace (sink->file, NULL, FALSE, 
+            G_FILE_CREATE_NONE, cancel, &err));
+    function_name = "g_file_replace";
+  }
+  else {
+    stream =
+        G_OUTPUT_STREAM (g_file_create (sink->file, G_FILE_CREATE_NONE, cancel,
+            &err));
+    function_name = "g_file_create";
+  }
 
   success = (stream != NULL);
 
-  if (!success && !gst_gio_error (sink, "g_file_create", &err, NULL)) {
-
-    /*if (GST_GIO_ERROR_MATCHES (err, EXISTS)) */
-    /* FIXME: Retry with replace if overwrite == TRUE! */
-
+  if (!success && !gst_gio_error (sink, function_name, &err, NULL)) {
     if (GST_GIO_ERROR_MATCHES (err, NOT_FOUND))
       GST_ELEMENT_ERROR (sink, RESOURCE, NOT_FOUND, (NULL),
           ("Could not open location %s for writing: %s", uri, err->message));
     else
-      GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_READ, (NULL),
+      GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_WRITE, (NULL),
           ("Could not open location %s for writing: %s", uri, err->message));
 
     g_free (uri);
Index: gstgiosink.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/gio/gstgiosink.h,v
retrieving revision 1.7
diff -u -r1.7 gstgiosink.h
--- gstgiosink.h	20 Apr 2008 10:11:54 -0000	1.7
+++ gstgiosink.h	23 Apr 2008 23:08:07 -0000
@@ -54,6 +54,7 @@
 
   /*< private >*/
   GFile *file;
+  gboolean overwrite;
 };
 
 struct _GstGioSinkClass 
