From 2750084388d9cb6164a99be13070f5d8b56e866b Mon Sep 17 00:00:00 2001 From: zhuyaliang <15132211195@163.com> Date: Thu, 11 May 2023 16:02:49 +0800 Subject: Archive do not track symbolic link g_file_enumerate_children_async default should use G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS. This can avoid link loops --- src/gio-utils.c | 22 +++++++++++++++------- src/gio-utils.h | 5 +++-- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gio-utils.c b/src/gio-utils.c index 5f66e1f..2fd8b47 100644 --- a/src/gio-utils.c +++ b/src/gio-utils.c @@ -300,7 +300,7 @@ for_each_child_next_files_ready (GObject *source_object, } } - fec->for_each_file_func (uri, child_info, fec->user_data); + fec->for_each_file_func (uri, fec->follow_links, child_info, fec->user_data); g_free (uri); g_object_unref (f); @@ -360,9 +360,9 @@ for_each_child_start_current (ForEachChildData *fec) g_file_enumerate_children_async (fec->current, "standard::name,standard::type", - fec->follow_links ? G_FILE_QUERY_INFO_NONE : G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, G_PRIORITY_DEFAULT, - fec->cancellable, + fec->cancellable, for_each_child_ready, fec); } @@ -610,8 +610,9 @@ get_file_list_done (GError *error, static void get_file_list_for_each_file (const char *uri, - GFileInfo *info, - gpointer user_data) + gboolean follow_links, + GFileInfo *info, + gpointer user_data) { GetFileListData *gfl = user_data; @@ -621,6 +622,12 @@ get_file_list_for_each_file (const char *uri, if ((gfl->exclude_filter->pattern == NULL) || ! filter_matches (gfl->exclude_filter, uri)) gfl->files = g_list_prepend (gfl->files, g_strdup (uri)); break; + case G_FILE_TYPE_SYMBOLIC_LINK: + if (follow_links) + if (filter_matches (gfl->include_filter, uri)) + if ((gfl->exclude_filter->pattern == NULL) || ! filter_matches (gfl->exclude_filter, uri)) + gfl->files = g_list_prepend (gfl->files, g_strdup (uri)); + break; default: break; } @@ -1283,8 +1290,9 @@ g_directory_copy_list_ready (GError *error, static void g_directory_copy_for_each_file (const char *uri, - GFileInfo *info, - gpointer user_data) + gboolean follow_links, + GFileInfo *info, + gpointer user_data) { DirectoryCopyData *dcd = user_data; diff --git a/src/gio-utils.h b/src/gio-utils.h index 47add16..e8d99aa 100644 --- a/src/gio-utils.h +++ b/src/gio-utils.h @@ -38,8 +38,9 @@ typedef DirOp (*StartDirCallback) (const char *uri, GError **error, gpointer user_data); typedef void (*ForEachChildCallback) (const char *uri, - GFileInfo *info, - gpointer user_data); + gboolean follow_links, + GFileInfo *info, + gpointer user_data); typedef void (*ForEachDoneCallback) (GError *error, gpointer data); typedef void (*ListReadyCallback) (GList *files, -- cgit v1.2.1