mirror of
https://git.proxmox.com/git/fwupd
synced 2025-05-29 04:52:15 +00:00
trivial: Add a common function to get a recursive file list
This commit is contained in:
parent
1ccd5d0bbd
commit
89e968b79b
@ -90,6 +90,50 @@ fu_common_rmtree (const gchar *directory, GError **error)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
fu_common_get_file_list_internal (GPtrArray *files, const gchar *directory, GError **error)
|
||||
{
|
||||
const gchar *filename;
|
||||
g_autoptr(GDir) dir = NULL;
|
||||
|
||||
/* try to open */
|
||||
dir = g_dir_open (directory, 0, error);
|
||||
if (dir == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* find each */
|
||||
while ((filename = g_dir_read_name (dir))) {
|
||||
g_autofree gchar *src = g_build_filename (directory, filename, NULL);
|
||||
if (g_file_test (src, G_FILE_TEST_IS_DIR)) {
|
||||
if (!fu_common_get_file_list_internal (files, src, error))
|
||||
return FALSE;
|
||||
} else {
|
||||
g_ptr_array_add (files, g_steal_pointer (&src));
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* fu_common_get_files_recursive:
|
||||
* @directory: a directory name
|
||||
* @error: A #GError or %NULL
|
||||
*
|
||||
* Returns every file found under @directory, and any subdirectory.
|
||||
* If any path under @directory cannot be accessed due to permissions an error
|
||||
* will be returned.
|
||||
*
|
||||
* Returns: (element-type: utf8) (transfer container): array of files, or %NULL for error
|
||||
**/
|
||||
GPtrArray *
|
||||
fu_common_get_files_recursive (const gchar *path, GError **error)
|
||||
{
|
||||
g_autoptr(GPtrArray) files = g_ptr_array_new_with_free_func (g_free);
|
||||
if (!fu_common_get_file_list_internal (files, path, error))
|
||||
return NULL;
|
||||
return g_steal_pointer (&files);
|
||||
}
|
||||
/**
|
||||
* fu_common_mkdir_parent:
|
||||
* @filename: A full pathname
|
||||
|
@ -35,6 +35,8 @@ gboolean fu_common_spawn_sync (const gchar * const *argv,
|
||||
|
||||
gboolean fu_common_rmtree (const gchar *directory,
|
||||
GError **error);
|
||||
GPtrArray *fu_common_get_files_recursive (const gchar *path,
|
||||
GError **error);
|
||||
gboolean fu_common_mkdir_parent (const gchar *filename,
|
||||
GError **error);
|
||||
gboolean fu_common_set_contents_bytes (const gchar *filename,
|
||||
|
Loading…
Reference in New Issue
Block a user