core: Update libgsystem, port some uses of GFileEnumerator

This makes the code *so* much nicer.
This commit is contained in:
Colin Walters 2013-06-14 19:14:35 -04:00
parent c57e63a515
commit fbd9f17e39
2 changed files with 43 additions and 52 deletions

@ -1 +1 @@
Subproject commit b2a65b235600e340fada441de7e131de9d52d25e Subproject commit 077fc095208e8429400763f0e41ac7c8884e8c1e

View File

@ -290,10 +290,7 @@ find_rev_in_remotes (OstreeRepo *self,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
GError *temp_error = NULL;
ot_lobj GFileEnumerator *dir_enum = NULL; ot_lobj GFileEnumerator *dir_enum = NULL;
ot_lobj GFileInfo *file_info = NULL;
ot_lobj GFile *child = NULL;
ot_lobj GFile *ret_file = NULL; ot_lobj GFile *ret_file = NULL;
dir_enum = g_file_enumerate_children (self->remote_heads_dir, OSTREE_GIO_FAST_QUERYINFO, dir_enum = g_file_enumerate_children (self->remote_heads_dir, OSTREE_GIO_FAST_QUERYINFO,
@ -302,28 +299,24 @@ find_rev_in_remotes (OstreeRepo *self,
if (!dir_enum) if (!dir_enum)
goto out; goto out;
while ((file_info = g_file_enumerator_next_file (dir_enum, NULL, error)) != NULL) while (TRUE)
{ {
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) GFileInfo *file_info;
{ GFile *child;
g_clear_object (&child); if (!gs_file_enumerator_iterate (dir_enum, &file_info, &child,
child = g_file_get_child (self->remote_heads_dir, NULL, error))
g_file_info_get_name (file_info)); goto out;
g_clear_object (&ret_file); if (file_info == NULL)
ret_file = g_file_resolve_relative_path (child, rev); break;
if (!g_file_query_exists (ret_file, NULL)) if (g_file_info_get_file_type (file_info) != G_FILE_TYPE_DIRECTORY)
g_clear_object (&ret_file); continue;
}
g_clear_object (&ret_file);
g_clear_object (&file_info); ret_file = g_file_resolve_relative_path (child, rev);
if (!g_file_query_exists (ret_file, NULL))
if (ret_file) g_clear_object (&ret_file);
else
break; break;
}
if (temp_error != NULL)
{
g_propagate_error (error, temp_error);
goto out;
} }
ret = TRUE; ret = TRUE;
@ -2646,11 +2639,9 @@ list_loose_object_dir (OstreeRepo *self,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
GError *temp_error = NULL;
const char *dirname = NULL; const char *dirname = NULL;
const char *dot = NULL; const char *dot = NULL;
ot_lobj GFileEnumerator *enumerator = NULL; gs_unref_object GFileEnumerator *enumerator = NULL;
ot_lobj GFileInfo *file_info = NULL;
GString *checksum = NULL; GString *checksum = NULL;
dirname = gs_file_get_basename_cached (dir); dirname = gs_file_get_basename_cached (dir);
@ -2663,17 +2654,25 @@ list_loose_object_dir (OstreeRepo *self,
if (!enumerator) if (!enumerator)
goto out; goto out;
while ((file_info = g_file_enumerator_next_file (enumerator, cancellable, &temp_error)) != NULL) while (TRUE)
{ {
GFileInfo *file_info;
const char *name; const char *name;
guint32 type; guint32 type;
OstreeObjectType objtype; OstreeObjectType objtype;
name = g_file_info_get_attribute_byte_string (file_info, "standard::name"); if (!gs_file_enumerator_iterate (enumerator, &file_info, NULL,
NULL, error))
goto out;
if (file_info == NULL)
break;
type = g_file_info_get_attribute_uint32 (file_info, "standard::type"); type = g_file_info_get_attribute_uint32 (file_info, "standard::type");
if (type == G_FILE_TYPE_DIRECTORY) if (type == G_FILE_TYPE_DIRECTORY)
goto loop_next; continue;
name = g_file_info_get_attribute_byte_string (file_info, "standard::name");
if (g_str_has_suffix (name, ".file")) if (g_str_has_suffix (name, ".file"))
objtype = OSTREE_OBJECT_TYPE_FILE; objtype = OSTREE_OBJECT_TYPE_FILE;
@ -2684,7 +2683,7 @@ list_loose_object_dir (OstreeRepo *self,
else if (g_str_has_suffix (name, ".commit")) else if (g_str_has_suffix (name, ".commit"))
objtype = OSTREE_OBJECT_TYPE_COMMIT; objtype = OSTREE_OBJECT_TYPE_COMMIT;
else else
goto loop_next; continue;
dot = strrchr (name, '.'); dot = strrchr (name, '.');
g_assert (dot); g_assert (dot);
@ -2705,16 +2704,7 @@ list_loose_object_dir (OstreeRepo *self,
g_hash_table_replace (inout_objects, key, g_hash_table_replace (inout_objects, key,
g_variant_ref_sink (value)); g_variant_ref_sink (value));
} }
loop_next:
g_clear_object (&file_info);
} }
if (temp_error != NULL)
{
g_propagate_error (error, temp_error);
goto out;
}
if (!g_file_enumerator_close (enumerator, NULL, error))
goto out;
ret = TRUE; ret = TRUE;
out: out:
@ -3851,9 +3841,7 @@ ostree_repo_checkout_gc (OstreeRepo *self,
g_hash_table_iter_init (&iter, to_clean_dirs); g_hash_table_iter_init (&iter, to_clean_dirs);
while (to_clean_dirs && g_hash_table_iter_next (&iter, &key, &value)) while (to_clean_dirs && g_hash_table_iter_next (&iter, &key, &value))
{ {
GError *temp_error = NULL;
ot_lobj GFile *objdir = NULL; ot_lobj GFile *objdir = NULL;
ot_lobj GFileInfo *file_info = NULL;
ot_lobj GFileEnumerator *enumerator = NULL; ot_lobj GFileEnumerator *enumerator = NULL;
ot_lfree char *objdir_name = NULL; ot_lfree char *objdir_name = NULL;
@ -3868,22 +3856,25 @@ ostree_repo_checkout_gc (OstreeRepo *self,
if (!enumerator) if (!enumerator)
goto out; goto out;
while ((file_info = g_file_enumerator_next_file (enumerator, cancellable, &temp_error)) != NULL) while (TRUE)
{ {
guint32 nlinks = g_file_info_get_attribute_uint32 (file_info, "unix::nlink"); GFileInfo *file_info;
guint32 nlinks;
if (!gs_file_enumerator_iterate (enumerator, &file_info, NULL,
cancellable, error))
goto out;
if (file_info == NULL)
break;
nlinks = g_file_info_get_attribute_uint32 (file_info, "unix::nlink");
if (nlinks == 1) if (nlinks == 1)
{ {
ot_lobj GFile *objpath = NULL; gs_unref_object GFile *objpath = NULL;
objpath = ot_gfile_get_child_build_path (objdir, g_file_info_get_name (file_info), NULL); objpath = g_file_get_child (objdir, g_file_info_get_name (file_info));
if (!gs_file_unlink (objpath, cancellable, error)) if (!gs_file_unlink (objpath, cancellable, error))
goto out; goto out;
} }
g_object_unref (file_info);
}
if (temp_error != NULL)
{
g_propagate_error (error, temp_error);
goto out;
} }
} }