[gvfs] gvfs-save: Allow specifying G_FILE_CREATE_REPLACE_DESTINATION



commit 540b03f9a73f58b1a1237b84ae1d453c4ac37a5f
Author: Ross Lagerwall <rosslagerwall gmail com>
Date:   Tue Aug 12 23:08:25 2014 +0100

    gvfs-save: Allow specifying G_FILE_CREATE_REPLACE_DESTINATION
    
    Allow specifying G_FILE_CREATE_REPLACE_DESTINATION when using gvfs-save
    with the -u flag or --unlink.  I chose this because "unlink" represents
    what G_FILE_CREATE_REPLACE_DESTINATION does in principle: it unlinks the
    destination before replacing it, thereby losing any permissions or other
    attributes of the file.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=734695

 man/gvfs-save.xml    |   11 +++++++++++
 programs/gvfs-save.c |    3 +++
 2 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/man/gvfs-save.xml b/man/gvfs-save.xml
index ef188f9..822e6a4 100644
--- a/man/gvfs-save.xml
+++ b/man/gvfs-save.xml
@@ -95,6 +95,17 @@
                         </varlistentry>
 
                         <varlistentry>
+                                <term><option>-u</option>, <option>--unlink</option></term>
+
+                                <listitem>
+                                    <para>When replacing an existing file,
+                                        replace the destination as if it does
+                                        not exist.  Think of it as unlinking
+                                        the destination before writing.</para>
+                                </listitem>
+                        </varlistentry>
+
+                        <varlistentry>
                                 <term><option>-v</option>, <option>--print-etag</option></term>
 
                                 <listitem><para>Print the new etag at the end.</para></listitem>
diff --git a/programs/gvfs-save.c b/programs/gvfs-save.c
index 51f70b1..8a1c614 100644
--- a/programs/gvfs-save.c
+++ b/programs/gvfs-save.c
@@ -36,6 +36,7 @@ static gboolean backup = FALSE;
 static gboolean create = FALSE;
 static gboolean append = FALSE;
 static gboolean priv = FALSE;
+static gboolean replace_dest = FALSE;
 static gboolean print_etag = FALSE;
 static gboolean show_version = FALSE;
 
@@ -45,6 +46,7 @@ static GOptionEntry entries[] =
   { "create", 'c', 0, G_OPTION_ARG_NONE, &create, N_("Only create if not existing"), NULL },
   { "append", 'a', 0, G_OPTION_ARG_NONE, &append, N_("Append to end of file"), NULL },
   { "private", 'p', 0, G_OPTION_ARG_NONE, &priv, N_("When creating, restrict access to the current user"), 
NULL },
+  { "unlink", 'u', 0, G_OPTION_ARG_NONE, &replace_dest, N_("When replacing, replace as if the destination 
did not exist"), NULL },
   /* Translators: The "etag" is a token allowing to verify whether a file has been modified */
   { "print-etag", 'v', 0, G_OPTION_ARG_NONE, &print_etag, N_("Print new etag at end"), NULL },
   /* Translators: The "etag" is a token allowing to verify whether a file has been modified */
@@ -68,6 +70,7 @@ save (GFile *file)
   error = NULL;
 
   flags = priv ? G_FILE_CREATE_PRIVATE : G_FILE_CREATE_NONE;
+  flags |= replace_dest ? G_FILE_CREATE_REPLACE_DESTINATION : 0;
 
   if (create)
     out = (GOutputStream *)g_file_create (file, flags, NULL, &error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]