From 811fcbcd95139bec6c97bbe9ebe5ba76292790f7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nelson=20Ben=C3=ADtez=20Le=C3=B3n?= Date: Sun, 21 Sep 2008 23:53:40 +0000 Subject: [PATCH] Add new GFileCopyFlag svn path=/trunk/; revision=7526 --- ChangeLog | 11 +++++++++++ gio/gfile.c | 17 ++++++++++++----- gio/gioenums.h | 4 +++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index db7779ba..4c633104 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-09-22 Nelson Benítez León + + * gio/gioenums.h: Add new GFileCopyFlag, to leave target file with + default perms, instead of setting the source file perms, in a copy + operation. + + * gio/gfile.c (g_file_copy_attributes) + (build_attribute_list_for_copy) + (should_copy): Not copy "unix::mode" attribute if we have received + G_FILE_COPY_TARGET_DEFAULT_PERMS flag. + 2008-09-19 Hans Petter Jansson Rewrite most of GHashTable to use open addressing with quadratic diff --git a/gio/gfile.c b/gio/gfile.c index 83643ea5..e89701f7 100644 --- a/gio/gfile.c +++ b/gio/gfile.c @@ -2056,8 +2056,12 @@ open_source_for_copy (GFile *source, static gboolean should_copy (GFileAttributeInfo *info, - gboolean as_move) + gboolean as_move, + gboolean skip_perms) { + if (skip_perms && strcmp(info->name, "unix::mode") == 0) + return FALSE; + if (as_move) return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED; return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE; @@ -2066,7 +2070,8 @@ should_copy (GFileAttributeInfo *info, static char * build_attribute_list_for_copy (GFileAttributeInfoList *attributes, GFileAttributeInfoList *namespaces, - gboolean as_move) + gboolean as_move, + gboolean skip_perms) { GString *s; gboolean first; @@ -2079,7 +2084,7 @@ build_attribute_list_for_copy (GFileAttributeInfoList *attributes, { for (i = 0; i < attributes->n_infos; i++) { - if (should_copy (&attributes->infos[i], as_move)) + if (should_copy (&attributes->infos[i], as_move, skip_perms)) { if (first) first = FALSE; @@ -2095,7 +2100,7 @@ build_attribute_list_for_copy (GFileAttributeInfoList *attributes, { for (i = 0; i < namespaces->n_infos; i++) { - if (should_copy (&namespaces->infos[i], as_move)) + if (should_copy (&namespaces->infos[i], as_move, FALSE)) { if (first) first = FALSE; @@ -2142,9 +2147,11 @@ g_file_copy_attributes (GFile *source, GFileInfo *info; gboolean as_move; gboolean source_nofollow_symlinks; + gboolean skip_perms; as_move = flags & G_FILE_COPY_ALL_METADATA; source_nofollow_symlinks = flags & G_FILE_COPY_NOFOLLOW_SYMLINKS; + skip_perms = flags & G_FILE_COPY_TARGET_DEFAULT_PERMS != 0; /* Ignore errors here, if the target supports no attributes there is nothing to copy */ attributes = g_file_query_settable_attributes (destination, cancellable, NULL); @@ -2153,7 +2160,7 @@ g_file_copy_attributes (GFile *source, if (attributes == NULL && namespaces == NULL) return TRUE; - attrs_to_read = build_attribute_list_for_copy (attributes, namespaces, as_move); + attrs_to_read = build_attribute_list_for_copy (attributes, namespaces, as_move, skip_perms); /* Ignore errors here, if we can't read some info (e.g. if it doesn't exist) * we just don't copy it. diff --git a/gio/gioenums.h b/gio/gioenums.h index 592cf06a..93ac5575 100644 --- a/gio/gioenums.h +++ b/gio/gioenums.h @@ -198,6 +198,7 @@ typedef enum { * @G_FILE_COPY_NOFOLLOW_SYMLINKS: Don't follow symlinks. * @G_FILE_COPY_ALL_METADATA: Copy all file metadata instead of just default set used for copy (see #GFileInfo). * @G_FILE_COPY_NO_FALLBACK_FOR_MOVE: Don't use copy and delete fallback if native move not supported. + * @G_FILE_COPY_TARGET_DEFAULT_PERMS: Leaves target file with default perms, instead of setting the source file perms. * * Flags used when copying or moving files. */ @@ -207,7 +208,8 @@ typedef enum { G_FILE_COPY_BACKUP = (1 << 1), G_FILE_COPY_NOFOLLOW_SYMLINKS = (1 << 2), G_FILE_COPY_ALL_METADATA = (1 << 3), - G_FILE_COPY_NO_FALLBACK_FOR_MOVE = (1 << 4) + G_FILE_COPY_NO_FALLBACK_FOR_MOVE = (1 << 4), + G_FILE_COPY_TARGET_DEFAULT_PERMS = (1 << 5) } GFileCopyFlags; -- 2.34.1