Index: gstgiosink.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/gio/gstgiosink.c,v
retrieving revision 1.11
diff -u -p -r1.11 gstgiosink.c
--- gstgiosink.c	20 Apr 2008 10:11:54 -0000	1.11
+++ gstgiosink.c	22 Apr 2008 00:02:02 -0000
@@ -78,6 +78,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_gio_sink_
 /* Filter signals and args */
 enum
 {
+  SIGNAL_ERASE_ASK,
   LAST_SIGNAL
 };
 
@@ -88,6 +89,8 @@ enum
   ARG_FILE
 };
 
+static guint gst_gio_sink_signals[LAST_SIGNAL];   /* all 0 */
+
 GST_BOILERPLATE_FULL (GstGioSink, gst_gio_sink, GstGioBaseSink,
     GST_TYPE_GIO_BASE_SINK, gst_gio_uri_handler_do_init);
 
@@ -112,6 +115,20 @@ gst_gio_sink_base_init (gpointer gclass)
       "Sebastian Dröge <slomo@circular-chaos.org>");
 }
 
+static gboolean
+_gst_boolean_allow_overwrite_accumulator (GSignalInvocationHint * ihint,
+    GValue * return_accu, const GValue * handler_return, gpointer dummy)
+{
+  gboolean allow_overwrite;
+
+  allow_overwrite = g_value_get_boolean (handler_return);
+  if (!(ihint->run_type & G_SIGNAL_RUN_CLEANUP))
+    g_value_set_boolean (return_accu, allow_overwrite);
+
+  /* stop emission if signal doesn't allow overwriting */
+  return allow_overwrite;
+}
+
 static void
 gst_gio_sink_class_init (GstGioSinkClass * klass)
 {
@@ -142,6 +159,23 @@ gst_gio_sink_class_init (GstGioSinkClass
       g_param_spec_object ("file", "File", "GFile to write to",
           G_TYPE_FILE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  /**
+   * GstGioSink::allow-overwrite
+   * @sink: the object which received the signal
+   * @uri: the URI to be overwritten
+   *
+   * This signal is fired when giosink is about to overwrite an
+   * existing resource. The application can connect to this signal and ask
+   * the user if the resource may be overwritten. 
+   *
+   * Returns: A boolean indicating that the resource may be overwritten.
+   */
+  gst_gio_sink_signals[SIGNAL_ERASE_ASK] =
+      g_signal_new ("allow-overwrite", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_CLEANUP, G_STRUCT_OFFSET (GstGioSinkClass, erase_ask),
+      _gst_boolean_allow_overwrite_accumulator, NULL,
+      gst_marshal_BOOLEAN__POINTER, G_TYPE_BOOLEAN, 1, G_TYPE_FILE);
+
   gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_gio_sink_start);
 }
 
@@ -258,7 +292,7 @@ gst_gio_sink_start (GstBaseSink * base_s
   GstGioSink *sink = GST_GIO_SINK (base_sink);
   GOutputStream *stream;
   GCancellable *cancel = GST_GIO_BASE_SINK (sink)->cancel;
-  gboolean success;
+  gboolean success, handled;
   GError *err = NULL;
   gchar *uri;
 
@@ -277,25 +311,44 @@ gst_gio_sink_start (GstBaseSink * base_s
           &err));
 
   success = (stream != NULL);
+  handled = success || gst_gio_error (sink, "g_file_create", &err, NULL);
 
-  if (!success && !gst_gio_error (sink, "g_file_create", &err, NULL)) {
+  if (!success && !handled) {
+    /* if the file existed and the property says to ask, then ask! */
+    if (GST_GIO_ERROR_MATCHES (err, EXISTS)) {
+      gboolean erase_anyway = FALSE;
+
+      g_signal_emit (G_OBJECT (sink),
+          gst_gio_sink_signals[SIGNAL_ERASE_ASK], 0, sink->file,
+          &erase_anyway);
+      if (erase_anyway) {
+        g_clear_error (&err);
+        
+        stream =
+            G_OUTPUT_STREAM (g_file_replace (sink->file, NULL, FALSE,
+                G_FILE_CREATE_NONE, cancel, &err));
 
-    /*if (GST_GIO_ERROR_MATCHES (err, EXISTS)) */
-    /* FIXME: Retry with replace if overwrite == TRUE! */
+        success = (stream != NULL);
+        handled = success || gst_gio_error (sink, "g_file_replace", &err, NULL);
+      }
+    }
+  }
 
+  if (!success && !handled) {
     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);
     g_clear_error (&err);
   }
 
-  if (!success)
+  if (!success) {
+    g_free (uri);
     return FALSE;
+  }
 
   GST_DEBUG_OBJECT (sink, "opened location %s", uri);
 
Index: gstgiosink.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/gio/gstgiosink.h,v
retrieving revision 1.7
diff -u -p -r1.7 gstgiosink.h
--- gstgiosink.h	20 Apr 2008 10:11:54 -0000	1.7
+++ gstgiosink.h	22 Apr 2008 00:02:02 -0000
@@ -59,6 +59,9 @@ struct _GstGioSink
 struct _GstGioSinkClass 
 {
   GstGioBaseSinkClass parent_class;
+
+  /* signals */
+  gboolean (*erase_ask) (GstElement * element, GFile * file);
 };
 
 GType gst_gio_sink_get_type (void);
