Public feed
#721566
Index: programs/gio-save.c
===================================================================
--- programs/gio-save.c (revisione 625)
+++ programs/gio-save.c (copia locale)
@@ -12,6 +12,7 @@ static char *etag = NULL;
static gboolean backup = FALSE;
static gboolean create = FALSE;
static gboolean append = FALSE;
+static gboolean priv = FALSE;
static gboolean print_etag = FALSE;
static GOptionEntry entries[] =
@@ -19,7 +20,8 @@ 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 },
+ { "private", 'p', 0, G_OPTION_ARG_NONE, &priv, "When creating a file, restrict access to the current user only", NULL },
+ { "print_etag", 'v', 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 }
};
@@ -28,6 +30,7 @@ static gboolean
save (GFile *file)
{
GOutputStream *out;
+ GFileCreateFlags flags;
char buffer[1025];
char *p;
gssize res;
@@ -36,12 +39,15 @@ save (GFile *file)
gboolean save_res;
error = NULL;
+
+ flags = priv ? G_FILE_CREATE_FLAGS_PRIVATE : G_FILE_CREATE_FLAGS_NONE;
+
if (create)
- out = (GOutputStream *)g_file_create (file, NULL, &error);
+ out = (GOutputStream *)g_file_create (file, flags, NULL, &error);
else if (append)
- out = (GOutputStream *)g_file_append_to (file, NULL, &error);
+ out = (GOutputStream *)g_file_append_to (file, flags, NULL, &error);
else
- out = (GOutputStream *)g_file_replace (file, etag, backup, NULL, &error);
+ out = (GOutputStream *)g_file_replace (file, etag, backup, flags, NULL, &error);
if (out == NULL)
{
g_printerr ("Error opening file: %s\n", error->message);
Index: gio/glocalfileoutputstream.c
===================================================================
--- gio/glocalfileoutputstream.c (revisione 625)
+++ gio/glocalfileoutputstream.c (copia locale)
@@ -379,15 +379,22 @@ g_local_file_output_stream_query_info (G
}
GFileOutputStream *
-g_local_file_output_stream_create (const char *filename,
- GCancellable *cancellable,
- GError **error)
+g_local_file_output_stream_create (const char *filename,
+ GFileCreateFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
GLocalFileOutputStream *stream;
+ int mode;
int fd;
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return NULL;
+
+ if (flags & G_FILE_CREATE_FLAGS_PRIVATE)
+ mode = 0600;
+ else
+ mode = 0666;
fd = g_open (filename,
O_CREAT | O_EXCL | O_WRONLY,
@@ -415,19 +422,26 @@ g_local_file_output_stream_create (cons
}
GFileOutputStream *
-g_local_file_output_stream_append (const char *filename,
- GCancellable *cancellable,
- GError **error)
+g_local_file_output_stream_append (const char *filename,
+ GFileCreateFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
GLocalFileOutputStream *stream;
+ int mode;
int fd;
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return NULL;
-
+
+ if (flags & G_FILE_CREATE_FLAGS_PRIVATE)
+ mode = 0600;
+ else
+ mode = 0666;
+
fd = g_open (filename,
O_CREAT | O_APPEND | O_WRONLY,
- 0666);
+ mode);
if (fd == -1)
{
int errsv = errno;
@@ -781,13 +795,15 @@ handle_overwrite_open (const char *filen
}
GFileOutputStream *
-g_local_file_output_stream_replace (const char *filename,
- const char *etag,
- gboolean create_backup,
- GCancellable *cancellable,
- GError **error)
+g_local_file_output_stream_replace (const char *filename,
+ const char *etag,
+ gboolean create_backup,
+ GFileCreateFlags flags,
+ GCancellable *cancellable,
+ GError **error)
{
GLocalFileOutputStream *stream;
+ int mode;
int fd;
char *temp_file;
@@ -795,10 +811,16 @@ g_local_file_output_stream_replace (cons
return NULL;
temp_file = NULL;
+
+ if (flags & G_FILE_CREATE_FLAGS_PRIVATE)
+ mode = 0600;
+ else
+ mode = 0666;
+
/* If the file doesn't exist, create it */
fd = g_open (filename,
O_CREAT | O_EXCL | O_WRONLY,
- 0666);
+ mode);
if (fd == -1 && errno == EEXIST)
{
Index: gio/glocalfileoutputstream.h
===================================================================
--- gio/glocalfileoutputstream.h (revisione 625)
+++ gio/glocalfileoutputstream.h (copia locale)
@@ -2,6 +2,7 @@
#define __G_LOCAL_FILE_OUTPUT_STREAM_H__
#include <gio/gfileoutputstream.h>
+#include <gio/gfile.h>
G_BEGIN_DECLS
@@ -30,18 +31,20 @@ struct _GLocalFileOutputStreamClass
};
GType g_local_file_output_stream_get_type (void) G_GNUC_CONST;
-GFileOutputStream *g_local_file_output_stream_create (const char *filename,
- GCancellable *cancellable,
- GError **error);
-GFileOutputStream *g_local_file_output_stream_append (const char *filename,
- GCancellable *cancellable,
- GError **error);
-GFileOutputStream *g_local_file_output_stream_replace (const char *filename,
- const char *etag,
- gboolean make_backup,
- GCancellable *cancellable,
- GError **error);
-
+GFileOutputStream *g_local_file_output_stream_create (const char *filename,
+ GFileCreateFlags flags,
+ GCancellable *cancellable,
+ GError **error);
+GFileOutputStream *g_local_file_output_stream_append (const char *filename,
+ GFileCreateFlags flags,
+ GCancellable *cancellable,
+ GError **error);
+GFileOutputStream *g_local_file_output_stream_replace (const char *filename,
+ const char *etag,
+ gboolean make_backup,
+ GFileCreateFlags flags,
+ GCancellable *cancellable,
+ GError **error);
G_END_DECLS
Index: gio/test-gio.c
===================================================================
--- gio/test-gio.c (revisione 625)
+++ gio/test-gio.c (copia locale)
@@ -52,7 +52,7 @@ test_out ()
unlink ("/tmp/test");
file = g_file_new_for_path ("/tmp/test");
- out = (GOutputStream *)g_file_create (file, NULL, NULL);
+ out = (GOutputStream *)g_file_create (file, G_FILE_CREATE_FLAGS_NONE, NULL, NULL);
left = sizeof(buffer);
ptr = buffer;
Index: gio/gfile.c
===================================================================
--- gio/gfile.c (revisione 625)
+++ gio/gfile.c (copia locale)
@@ -45,6 +45,7 @@ static GFileInputStream * g_file_real_re
GAsyncResult *res,
GError **error);
static void g_file_real_append_to_async (GFile *file,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -53,6 +54,7 @@ static GFileOutputStream *g_file_real_ap
GAsyncResult *res,
GError **error);
static void g_file_real_create_async (GFile *file,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -63,6 +65,7 @@ static GFileOutputStream *g_file_real_cr
static void g_file_real_replace_async (GFile *file,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -199,7 +202,6 @@ g_file_get_uri (GFile *file)
return (* iface->get_uri) (file);
}
-
char *
g_file_get_parse_name (GFile *file)
{
@@ -494,6 +496,7 @@ g_file_read (GFile *file,
GFileOutputStream *
g_file_append_to (GFile *file,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error)
{
@@ -512,11 +515,12 @@ g_file_append_to (GFile *file,
return NULL;
}
- return (* iface->append_to) (file, cancellable, error);
+ return (* iface->append_to) (file, flags, cancellable, error);
}
GFileOutputStream *
g_file_create (GFile *file,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error)
{
@@ -535,13 +539,14 @@ g_file_create (GFile *file,
return NULL;
}
- return (* iface->create) (file, cancellable, error);
+ return (* iface->create) (file, flags, cancellable, error);
}
GFileOutputStream *
g_file_replace (GFile *file,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error)
{
@@ -565,7 +570,7 @@ g_file_replace (GFile *file,
if (etag && *etag == 0)
etag = NULL;
- return (* iface->replace) (file, etag, make_backup, cancellable, error);
+ return (* iface->replace) (file, etag, make_backup, flags, cancellable, error);
}
void
@@ -605,6 +610,7 @@ g_file_read_finish (GFile
void
g_file_append_to_async (GFile *file,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -614,6 +620,7 @@ g_file_append_to_async (GFile
iface = G_FILE_GET_IFACE (file);
(* iface->append_to_async) (file,
+ flags,
io_priority,
cancellable,
callback,
@@ -640,6 +647,7 @@ g_file_append_to_finish (GFile
void
g_file_create_async (GFile *file,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -649,6 +657,7 @@ g_file_create_async (GFile
iface = G_FILE_GET_IFACE (file);
(* iface->create_async) (file,
+ flags,
io_priority,
cancellable,
callback,
@@ -677,6 +686,7 @@ void
g_file_replace_async (GFile *file,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -688,6 +698,7 @@ g_file_replace_async (GFile
(* iface->replace_async) (file,
etag,
make_backup,
+ flags,
io_priority,
cancellable,
callback,
@@ -1066,9 +1077,16 @@ file_copy_fallback (GFile
return FALSE;
if (flags & G_FILE_COPY_OVERWRITE)
- out = (GOutputStream *)g_file_replace (destination, 0, flags & G_FILE_COPY_BACKUP, cancellable, error);
+ {
+ out = (GOutputStream *)g_file_replace (destination,
+ 0, 0,
+ flags & G_FILE_COPY_BACKUP,
+ cancellable, error);
+ }
else
- out = (GOutputStream *)g_file_create (destination, cancellable, error);
+ {
+ out = (GOutputStream *)g_file_create (destination, 0, cancellable, error);
+ }
if (out == NULL)
{
@@ -2028,12 +2046,15 @@ append_to_async_thread (GSimpleAsyncResu
GCancellable *cancellable)
{
GFileIface *iface;
+ GFileCreateFlags *data;
GFileOutputStream *stream;
GError *error = NULL;
iface = G_FILE_GET_IFACE (object);
- stream = iface->append_to (G_FILE (object), cancellable, &error);
+ data = g_simple_async_result_get_op_res_gpointer (res);
+
+ stream = iface->append_to (G_FILE (object), *data, cancellable, &error);
if (stream == NULL)
{
@@ -2046,15 +2067,21 @@ append_to_async_thread (GSimpleAsyncResu
static void
g_file_real_append_to_async (GFile *file,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
+ GFileCreateFlags *data;
GSimpleAsyncResult *res;
-
+
+ data = g_new0 (GFileCreateFlags, 1);
+ *data = flags;
+
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_append_to_async);
-
+ g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
+
g_simple_async_result_run_in_thread (res, append_to_async_thread, io_priority, cancellable);
g_object_unref (res);
}
@@ -2082,12 +2109,15 @@ create_async_thread (GSimpleAsyncResult
GCancellable *cancellable)
{
GFileIface *iface;
+ GFileCreateFlags *data;
GFileOutputStream *stream;
GError *error = NULL;
iface = G_FILE_GET_IFACE (object);
- stream = iface->create (G_FILE (object), cancellable, &error);
+ data = g_simple_async_result_get_op_res_gpointer (res);
+
+ stream = iface->create (G_FILE (object), *data, cancellable, &error);
if (stream == NULL)
{
@@ -2100,15 +2130,21 @@ create_async_thread (GSimpleAsyncResult
static void
g_file_real_create_async (GFile *file,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
+ GFileCreateFlags *data;
GSimpleAsyncResult *res;
-
+
+ data = g_new0 (GFileCreateFlags, 1);
+ *data = flags;
+
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_create_async);
-
+ g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)g_free);
+
g_simple_async_result_run_in_thread (res, create_async_thread, io_priority, cancellable);
g_object_unref (res);
}
@@ -2134,6 +2170,7 @@ typedef struct {
GFileOutputStream *stream;
char *etag;
gboolean make_backup;
+ GFileCreateFlags flags;
} ReplaceAsyncData;
static void
@@ -2159,7 +2196,12 @@ replace_async_thread (GSimpleAsyncResult
data = g_simple_async_result_get_op_res_gpointer (res);
- stream = iface->replace (G_FILE (object), data->etag, data->make_backup, cancellable, &error);
+ stream = iface->replace (G_FILE (object),
+ data->etag,
+ data->make_backup,
+ data->flags,
+ cancellable,
+ &error);
if (stream == NULL)
{
@@ -2174,6 +2216,7 @@ static void
g_file_real_replace_async (GFile *file,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -2185,10 +2228,11 @@ g_file_real_replace_async (GFile
data = g_new0 (ReplaceAsyncData, 1);
data->etag = g_strdup (etag);
data->make_backup = make_backup;
-
+ data->flags = flags;
+
res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, g_file_real_replace_async);
g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)replace_async_data_free);
-
+
g_simple_async_result_run_in_thread (res, replace_async_thread, io_priority, cancellable);
g_object_unref (res);
}
@@ -2307,7 +2351,6 @@ set_info_async_thread (GSimpleAsyncResul
GCancellable *cancellable)
{
SetInfoAsyncData *data;
- GFileInfo *info;
data = g_simple_async_result_get_op_res_gpointer (res);
@@ -2317,7 +2360,6 @@ set_info_async_thread (GSimpleAsyncResul
data->flags,
cancellable,
&data->error);
-
}
static void
@@ -2834,6 +2876,7 @@ g_file_replace_contents (GFile
gsize length,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
char **new_etag,
GCancellable *cancellable,
GError **error)
@@ -2845,6 +2888,7 @@ g_file_replace_contents (GFile
out = g_file_replace (file,
etag,
make_backup,
+ flags,
cancellable,
error);
if (out == NULL)
@@ -3012,6 +3056,7 @@ g_file_replace_contents_async (GFile
gsize length,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -3032,6 +3077,7 @@ g_file_replace_contents_async (GFile
g_file_replace_async (file,
etag,
make_backup,
+ flags,
0,
cancellable,
replace_contents_open_callback,
Index: gio/gfile.h
===================================================================
--- gio/gfile.h (revisione 625)
+++ gio/gfile.h (copia locale)
@@ -20,6 +20,11 @@ typedef enum {
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS = (1<<0)
} GFileQueryInfoFlags;
+typedef enum {
+ G_FILE_CREATE_FLAGS_NONE = 0,
+ G_FILE_CREATE_FLAGS_PRIVATE = (1<<0)
+} GFileCreateFlags;
+
typedef enum {
G_FILE_COPY_OVERWRITE = (1<<0),
G_FILE_COPY_BACKUP = (1<<1),
@@ -149,14 +154,17 @@ struct _GFileIface
GCancellable *cancellable,
GError **error);
GFileOutputStream * (*append_to) (GFile *file,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error);
GFileOutputStream * (*create) (GFile *file,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error);
GFileOutputStream * (*replace) (GFile *file,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error);
gboolean (*delete_file) (GFile *file,
@@ -197,6 +205,7 @@ struct _GFileIface
GError **error);
void (*append_to_async) (GFile *file,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -205,6 +214,7 @@ struct _GFileIface
GAsyncResult *res,
GError **error);
void (*create_async) (GFile *file,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -215,6 +225,7 @@ struct _GFileIface
void (*replace_async) (GFile *file,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -303,17 +314,21 @@ GFileInputStream * g_file_read_fini
GAsyncResult *res,
GError **error);
GFileOutputStream * g_file_append_to (GFile *file,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error);
GFileOutputStream * g_file_create (GFile *file,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error);
GFileOutputStream * g_file_replace (GFile *file,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error);
void g_file_append_to_async (GFile *file,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -322,6 +337,7 @@ GFileOutputStream * g_file_append_to
GAsyncResult *res,
GError **error);
void g_file_create_async (GFile *file,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -332,6 +348,7 @@ GFileOutputStream * g_file_create_fi
void g_file_replace_async (GFile *file,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -550,6 +567,7 @@ gboolean g_file_replace_contents
gsize length,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
char **new_etag,
GCancellable *cancellable,
GError **error);
@@ -558,6 +576,7 @@ void g_file_replace_contents_async
gsize length,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
Index: gio/glocalfile.c
===================================================================
--- gio/glocalfile.c (revisione 625)
+++ gio/glocalfile.c (copia locale)
@@ -840,31 +840,34 @@ g_local_file_read (GFile *file,
static GFileOutputStream *
g_local_file_append_to (GFile *file,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error)
{
return g_local_file_output_stream_append (G_LOCAL_FILE (file)->filename,
- cancellable, error);
+ flags, cancellable, error);
}
static GFileOutputStream *
g_local_file_create (GFile *file,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error)
{
return g_local_file_output_stream_create (G_LOCAL_FILE (file)->filename,
- cancellable, error);
+ flags, cancellable, error);
}
static GFileOutputStream *
g_local_file_replace (GFile *file,
const char *etag,
gboolean make_backup,
+ GFileCreateFlags flags,
GCancellable *cancellable,
GError **error)
{
return g_local_file_output_stream_replace (G_LOCAL_FILE (file)->filename,
- etag, make_backup,
+ etag, make_backup, flags,
cancellable, error);
}