gfile: Factor out flags when copying files

This introduces no functional changes; just reduces duplication in the
code a little.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2019-09-27 14:46:18 +01:00
parent 61509eab26
commit 51d73ef5d9

View File

@ -3188,6 +3188,7 @@ file_copy_fallback (GFile *source,
const char *target; const char *target;
char *attrs_to_read; char *attrs_to_read;
gboolean do_set_attributes = FALSE; gboolean do_set_attributes = FALSE;
GFileCreateFlags create_flags;
/* need to know the file type */ /* need to know the file type */
info = g_file_query_info (source, info = g_file_query_info (source,
@ -3278,18 +3279,21 @@ file_copy_fallback (GFile *source,
* If a future API like g_file_replace_with_info() is added, switch * If a future API like g_file_replace_with_info() is added, switch
* this code to use that. * this code to use that.
*/ */
create_flags = G_FILE_CREATE_PRIVATE;
if (flags & G_FILE_COPY_OVERWRITE)
create_flags |= G_FILE_CREATE_REPLACE_DESTINATION;
if (G_IS_LOCAL_FILE (destination)) if (G_IS_LOCAL_FILE (destination))
{ {
if (flags & G_FILE_COPY_OVERWRITE) if (flags & G_FILE_COPY_OVERWRITE)
out = (GOutputStream*)_g_local_file_output_stream_replace (_g_local_file_get_filename (G_LOCAL_FILE (destination)), out = (GOutputStream*)_g_local_file_output_stream_replace (_g_local_file_get_filename (G_LOCAL_FILE (destination)),
FALSE, NULL, FALSE, NULL,
flags & G_FILE_COPY_BACKUP, flags & G_FILE_COPY_BACKUP,
G_FILE_CREATE_REPLACE_DESTINATION | create_flags, info,
G_FILE_CREATE_PRIVATE, info,
cancellable, error); cancellable, error);
else else
out = (GOutputStream*)_g_local_file_output_stream_create (_g_local_file_get_filename (G_LOCAL_FILE (destination)), out = (GOutputStream*)_g_local_file_output_stream_create (_g_local_file_get_filename (G_LOCAL_FILE (destination)),
FALSE, G_FILE_CREATE_PRIVATE, info, FALSE, create_flags, info,
cancellable, error); cancellable, error);
} }
else if (flags & G_FILE_COPY_OVERWRITE) else if (flags & G_FILE_COPY_OVERWRITE)
@ -3297,13 +3301,12 @@ file_copy_fallback (GFile *source,
out = (GOutputStream *)g_file_replace (destination, out = (GOutputStream *)g_file_replace (destination,
NULL, NULL,
flags & G_FILE_COPY_BACKUP, flags & G_FILE_COPY_BACKUP,
G_FILE_CREATE_REPLACE_DESTINATION | create_flags,
G_FILE_CREATE_PRIVATE,
cancellable, error); cancellable, error);
} }
else else
{ {
out = (GOutputStream *)g_file_create (destination, G_FILE_CREATE_PRIVATE, cancellable, error); out = (GOutputStream *)g_file_create (destination, create_flags, cancellable, error);
} }
if (!out) if (!out)