diff options
author | Alexander Larsson <alexl@src.gnome.org> | 2007-09-13 14:34:36 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2007-09-13 14:34:36 +0000 |
commit | 8f6affe4aaf80ed80f52b78e39227e32560dd1b4 (patch) | |
tree | 408486611f6eaa58400d9499d92173c9ffc8f0ed /programs | |
parent | b9a4e838b5581562aa3747f8c7d3f639d65742b1 (diff) |
Rename gvfs-create to gvfs-save, add various commandline args
Original git commit by Alexander Larsson <alexl@redhat.com> at 1185360274 +0200
svn path=/trunk/; revision=712
Diffstat (limited to 'programs')
-rw-r--r-- | programs/Makefile.am | 6 | ||||
-rw-r--r-- | programs/gvfs-save.c (renamed from programs/gvfs-create.c) | 40 |
2 files changed, 40 insertions, 6 deletions
diff --git a/programs/Makefile.am b/programs/Makefile.am index b9921595..4da2eeb7 100644 --- a/programs/Makefile.am +++ b/programs/Makefile.am @@ -13,7 +13,7 @@ libraries = \ bin_PROGRAMS = \ gvfs-mount \ gvfs-cat \ - gvfs-create \ + gvfs-save \ gvfs-ls \ gvfs-info \ gvfs-trash \ @@ -30,8 +30,8 @@ gvfs_cat_LDADD = $(libraries) gvfs_copy_SOURCES = gvfs-copy.c gvfs_copy_LDADD = $(libraries) -gvfs_create_SOURCES = gvfs-create.c -gvfs_create_LDADD = $(libraries) +gvfs_save_SOURCES = gvfs-save.c +gvfs_save_LDADD = $(libraries) gvfs_info_SOURCES = gvfs-info.c gvfs_info_LDADD = $(libraries) diff --git a/programs/gvfs-create.c b/programs/gvfs-save.c index 3fbf8d56..a341402a 100644 --- a/programs/gvfs-create.c +++ b/programs/gvfs-save.c @@ -8,13 +8,24 @@ #include <glib.h> #include <gio/gfile.h> +static char *etag = NULL; +static gboolean backup = FALSE; +static gboolean create = FALSE; +static gboolean append = FALSE; +static gboolean print_etag = FALSE; + static GOptionEntry entries[] = { + { "backup", 'b', 0, G_OPTION_ARG_NONE, &backup, "Create backup", NULL }, + { "create", 'c', 0, G_OPTION_ARG_NONE, &create, "Only create if not existing", NULL }, + { "append", 'a', 0, G_OPTION_ARG_NONE, &append, "Append to end of file", NULL }, + { "print_etag", 'p', 0, G_OPTION_ARG_NONE, &print_etag, "Print new etag at end", NULL }, + { "etag", 'e', 0, G_OPTION_ARG_STRING, &etag, "The etag of the file being overwritten", NULL }, { NULL } }; static void -create (GFile *file) +save (GFile *file) { GOutputStream *out; char buffer[1025]; @@ -24,7 +35,12 @@ create (GFile *file) GError *error; error = NULL; - out = (GOutputStream *)g_file_create (file, NULL, &error); + if (create) + out = (GOutputStream *)g_file_create (file, NULL, &error); + else if (append) + out = (GOutputStream *)g_file_append_to (file, NULL, &error); + else + out = (GOutputStream *)g_file_replace (file, etag, backup, NULL, &error); if (out == NULL) { g_printerr ("Error opening file: %s\n", error->message); @@ -71,6 +87,24 @@ create (GFile *file) g_printerr ("Error closing: %s\n", error->message); g_error_free (error); } + + if (close_res && print_etag) + { + char *etag; + etag = g_file_output_stream_get_etag (G_FILE_OUTPUT_STREAM (out), NULL, &error); + + if (etag) + g_print ("Etag: %s\n", etag); + else + { + g_printerr ("Error getting etag: %s\n", error->message); + g_error_free (error); + } + + g_free (etag); + } + + g_object_unref (out); } int @@ -92,7 +126,7 @@ main (int argc, char *argv[]) if (argc > 1) { file = g_file_get_for_commandline_arg (argv[1]); - create (file); + save (file); g_object_unref (file); } |