mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-24 04:56:14 +01:00
gio: add a file copy flag for default modification time
Add a default modification timestamp flag to g_file_copy so that it doesn't copy the modification time from the source file as it does by default. Similarly to G_FILE_COPY_TARGET_DEFAULT_PERMS, this flag overrides the G_FILE_COPY_ALL_METADATA flag. Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/3140
This commit is contained in:
parent
6d460f6c7e
commit
8d91430279
14
gio/gfile.c
14
gio/gfile.c
@ -2743,10 +2743,12 @@ open_source_for_copy (GFile *source,
|
|||||||
static gboolean
|
static gboolean
|
||||||
should_copy (GFileAttributeInfo *info,
|
should_copy (GFileAttributeInfo *info,
|
||||||
gboolean copy_all_attributes,
|
gboolean copy_all_attributes,
|
||||||
gboolean skip_perms)
|
gboolean skip_perms,
|
||||||
|
gboolean skip_modified_time)
|
||||||
{
|
{
|
||||||
if (skip_perms && strcmp(info->name, "unix::mode") == 0)
|
if ((skip_perms && strcmp(info->name, "unix::mode") == 0) ||
|
||||||
return FALSE;
|
(skip_modified_time && strncmp(info->name, "time::modified", 14) == 0))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
if (copy_all_attributes)
|
if (copy_all_attributes)
|
||||||
return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED;
|
return info->flags & G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED;
|
||||||
@ -2789,6 +2791,7 @@ g_file_build_attribute_list_for_copy (GFile *file,
|
|||||||
int i;
|
int i;
|
||||||
gboolean copy_all_attributes;
|
gboolean copy_all_attributes;
|
||||||
gboolean skip_perms;
|
gboolean skip_perms;
|
||||||
|
gboolean skip_modified_time;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||||
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
||||||
@ -2796,6 +2799,7 @@ g_file_build_attribute_list_for_copy (GFile *file,
|
|||||||
|
|
||||||
copy_all_attributes = flags & G_FILE_COPY_ALL_METADATA;
|
copy_all_attributes = flags & G_FILE_COPY_ALL_METADATA;
|
||||||
skip_perms = (flags & G_FILE_COPY_TARGET_DEFAULT_PERMS) != 0;
|
skip_perms = (flags & G_FILE_COPY_TARGET_DEFAULT_PERMS) != 0;
|
||||||
|
skip_modified_time = (flags & G_FILE_COPY_TARGET_DEFAULT_MODIFIED_TIME) != 0;
|
||||||
|
|
||||||
/* Ignore errors here, if the target supports no attributes there is
|
/* Ignore errors here, if the target supports no attributes there is
|
||||||
* nothing to copy. We still honor the cancellable though.
|
* nothing to copy. We still honor the cancellable though.
|
||||||
@ -2823,7 +2827,7 @@ g_file_build_attribute_list_for_copy (GFile *file,
|
|||||||
{
|
{
|
||||||
for (i = 0; i < attributes->n_infos; i++)
|
for (i = 0; i < attributes->n_infos; i++)
|
||||||
{
|
{
|
||||||
if (should_copy (&attributes->infos[i], copy_all_attributes, skip_perms))
|
if (should_copy (&attributes->infos[i], copy_all_attributes, skip_perms, skip_modified_time))
|
||||||
{
|
{
|
||||||
if (first)
|
if (first)
|
||||||
first = FALSE;
|
first = FALSE;
|
||||||
@ -2839,7 +2843,7 @@ g_file_build_attribute_list_for_copy (GFile *file,
|
|||||||
{
|
{
|
||||||
for (i = 0; i < namespaces->n_infos; i++)
|
for (i = 0; i < namespaces->n_infos; i++)
|
||||||
{
|
{
|
||||||
if (should_copy (&namespaces->infos[i], copy_all_attributes, FALSE))
|
if (should_copy (&namespaces->infos[i], copy_all_attributes, FALSE, FALSE))
|
||||||
{
|
{
|
||||||
if (first)
|
if (first)
|
||||||
first = FALSE;
|
first = FALSE;
|
||||||
|
@ -314,6 +314,8 @@ typedef enum {
|
|||||||
* @G_FILE_COPY_ALL_METADATA: Copy all file metadata instead of just default set used for copy (see #GFileInfo).
|
* @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_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.
|
* @G_FILE_COPY_TARGET_DEFAULT_PERMS: Leaves target file with default perms, instead of setting the source file perms.
|
||||||
|
* @G_FILE_COPY_TARGET_DEFAULT_MODIFIED_TIME: Use default modification
|
||||||
|
* timestamps instead of copying them from the source file. Since 2.80
|
||||||
*
|
*
|
||||||
* Flags used when copying or moving files.
|
* Flags used when copying or moving files.
|
||||||
*/
|
*/
|
||||||
@ -324,7 +326,8 @@ typedef enum {
|
|||||||
G_FILE_COPY_NOFOLLOW_SYMLINKS = (1 << 2),
|
G_FILE_COPY_NOFOLLOW_SYMLINKS = (1 << 2),
|
||||||
G_FILE_COPY_ALL_METADATA = (1 << 3),
|
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)
|
G_FILE_COPY_TARGET_DEFAULT_PERMS = (1 << 5),
|
||||||
|
G_FILE_COPY_TARGET_DEFAULT_MODIFIED_TIME GIO_AVAILABLE_ENUMERATOR_IN_2_80 = (1 << 6),
|
||||||
} GFileCopyFlags;
|
} GFileCopyFlags;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user