gio-tool: Add a --default-permissions argument to gio copy

This sets the `G_FILE_COPY_DEFAULT_PERMS` flag on the operation,
creating the copied file with default permissions rather than the same
permissions as the source file.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #174
This commit is contained in:
Philip Withnall 2019-09-27 17:24:36 +01:00
parent 53f6ede628
commit 2268f36769
2 changed files with 8 additions and 0 deletions

View File

@ -226,6 +226,10 @@
<term><option>-P</option>, <option>--no-dereference</option></term>
<listitem><para>Never follow symbolic links.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--default-permissions</option></term>
<listitem><para>Use the default permissions of the current process for the destination file, rather than copying the permissions of the source file.</para></listitem>
</varlistentry>
</variablelist>
</refsect3>
</listitem>

View File

@ -37,6 +37,7 @@ static gboolean interactive = FALSE;
static gboolean preserve = FALSE;
static gboolean backup = FALSE;
static gboolean no_dereference = FALSE;
static gboolean default_permissions = FALSE;
static const GOptionEntry entries[] = {
{ "no-target-directory", 'T', 0, G_OPTION_ARG_NONE, &no_target_directory, N_("No target directory"), NULL },
@ -45,6 +46,7 @@ static const GOptionEntry entries[] = {
{ "preserve", 'p', 0, G_OPTION_ARG_NONE, &preserve, N_("Preserve all attributes"), NULL },
{ "backup", 'b', 0, G_OPTION_ARG_NONE, &backup, N_("Backup existing destination files"), NULL },
{ "no-dereference", 'P', 0, G_OPTION_ARG_NONE, &no_dereference, N_("Never follow symbolic links"), NULL },
{ "default-permissions", 0, 0, G_OPTION_ARG_NONE, &default_permissions, N_("Use default permissions for the destination"), NULL },
{ NULL }
};
@ -175,6 +177,8 @@ handle_copy (int argc, char *argv[], gboolean do_help)
flags |= G_FILE_COPY_NOFOLLOW_SYMLINKS;
if (preserve)
flags |= G_FILE_COPY_ALL_METADATA;
if (default_permissions)
flags |= G_FILE_COPY_TARGET_DEFAULT_PERMS;
error = NULL;
start_time = g_get_monotonic_time ();