diff: Port some to new code style
Continuing to chip away at this. Using `g_file_enumerator_iterate()` here helps notably. I started on the much bigger `ostree_diff_dirs_with_options()` but it's a lot messier - for later. Closes: #844 Approved by: jlebon
This commit is contained in:
parent
bf1a994d85
commit
18c5947c5f
|
|
@ -35,9 +35,7 @@ get_file_checksum (OstreeDiffFlags flags,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
g_autofree char *ret_checksum = NULL;
|
g_autofree char *ret_checksum = NULL;
|
||||||
g_autofree guchar *csum = NULL;
|
|
||||||
|
|
||||||
if (OSTREE_IS_REPO_FILE (f))
|
if (OSTREE_IS_REPO_FILE (f))
|
||||||
{
|
{
|
||||||
|
|
@ -52,27 +50,26 @@ get_file_checksum (OstreeDiffFlags flags,
|
||||||
{
|
{
|
||||||
if (!glnx_dfd_name_get_all_xattrs (AT_FDCWD, gs_file_get_path_cached (f),
|
if (!glnx_dfd_name_get_all_xattrs (AT_FDCWD, gs_file_get_path_cached (f),
|
||||||
&xattrs, cancellable, error))
|
&xattrs, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_file_info_get_file_type (f_info) == G_FILE_TYPE_REGULAR)
|
if (g_file_info_get_file_type (f_info) == G_FILE_TYPE_REGULAR)
|
||||||
{
|
{
|
||||||
in = (GInputStream*)g_file_read (f, cancellable, error);
|
in = (GInputStream*)g_file_read (f, cancellable, error);
|
||||||
if (!in)
|
if (!in)
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_autofree guchar *csum = NULL;
|
||||||
if (!ostree_checksum_file_from_input (f_info, xattrs, in,
|
if (!ostree_checksum_file_from_input (f_info, xattrs, in,
|
||||||
OSTREE_OBJECT_TYPE_FILE,
|
OSTREE_OBJECT_TYPE_FILE,
|
||||||
&csum, cancellable, error))
|
&csum, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
ret_checksum = ostree_checksum_from_bytes (csum);
|
ret_checksum = ostree_checksum_from_bytes (csum);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
ot_transfer_out_value(out_checksum, &ret_checksum);
|
ot_transfer_out_value(out_checksum, &ret_checksum);
|
||||||
out:
|
return TRUE;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OstreeDiffItem *
|
OstreeDiffItem *
|
||||||
|
|
@ -130,28 +127,22 @@ diff_files (OstreeDiffFlags flags,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
|
||||||
g_autofree char *checksum_a = NULL;
|
g_autofree char *checksum_a = NULL;
|
||||||
g_autofree char *checksum_b = NULL;
|
g_autofree char *checksum_b = NULL;
|
||||||
OstreeDiffItem *ret_item = NULL;
|
|
||||||
|
|
||||||
if (!get_file_checksum (flags, a, a_info, &checksum_a, cancellable, error))
|
if (!get_file_checksum (flags, a, a_info, &checksum_a, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
if (!get_file_checksum (flags, b, b_info, &checksum_b, cancellable, error))
|
if (!get_file_checksum (flags, b, b_info, &checksum_b, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
|
g_autoptr(OstreeDiffItem) ret_item = NULL;
|
||||||
if (strcmp (checksum_a, checksum_b) != 0)
|
if (strcmp (checksum_a, checksum_b) != 0)
|
||||||
{
|
{
|
||||||
ret_item = diff_item_new (a, a_info, b, b_info,
|
ret_item = diff_item_new (a, a_info, b, b_info,
|
||||||
checksum_a, checksum_b);
|
checksum_a, checksum_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
ot_transfer_out_value(out_item, &ret_item);
|
ot_transfer_out_value(out_item, &ret_item);
|
||||||
out:
|
return TRUE;
|
||||||
if (ret_item)
|
|
||||||
ostree_diff_item_unref (ret_item);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
@ -160,47 +151,38 @@ diff_add_dir_recurse (GFile *d,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
g_autoptr(GFileEnumerator) dir_enum =
|
||||||
GError *temp_error = NULL;
|
g_file_enumerate_children (d, OSTREE_GIO_FAST_QUERYINFO,
|
||||||
g_autoptr(GFileEnumerator) dir_enum = NULL;
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
g_autoptr(GFile) child = NULL;
|
cancellable,
|
||||||
g_autoptr(GFileInfo) child_info = NULL;
|
error);
|
||||||
|
|
||||||
dir_enum = g_file_enumerate_children (d, OSTREE_GIO_FAST_QUERYINFO,
|
|
||||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
|
||||||
cancellable,
|
|
||||||
error);
|
|
||||||
if (!dir_enum)
|
if (!dir_enum)
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
while ((child_info = g_file_enumerator_next_file (dir_enum, cancellable, &temp_error)) != NULL)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
|
GFileInfo *child_info;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
|
if (!g_file_enumerator_iterate (dir_enum, &child_info, NULL,
|
||||||
|
cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
if (child_info == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
name = g_file_info_get_name (child_info);
|
name = g_file_info_get_name (child_info);
|
||||||
|
|
||||||
g_clear_object (&child);
|
g_autoptr(GFile) child = g_file_get_child (d, name);
|
||||||
child = g_file_get_child (d, name);
|
|
||||||
|
|
||||||
g_ptr_array_add (added, g_object_ref (child));
|
g_ptr_array_add (added, g_object_ref (child));
|
||||||
|
|
||||||
if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY)
|
if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY)
|
||||||
{
|
{
|
||||||
if (!diff_add_dir_recurse (child, added, cancellable, error))
|
if (!diff_add_dir_recurse (child, added, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_object (&child_info);
|
|
||||||
}
|
|
||||||
if (temp_error != NULL)
|
|
||||||
{
|
|
||||||
g_propagate_error (error, temp_error);
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue