mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-19 22:50:35 +03:00
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,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
g_autofree char *ret_checksum = NULL;
|
||||
g_autofree guchar *csum = NULL;
|
||||
|
||||
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),
|
||||
&xattrs, cancellable, error))
|
||||
goto out;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (g_file_info_get_file_type (f_info) == G_FILE_TYPE_REGULAR)
|
||||
{
|
||||
in = (GInputStream*)g_file_read (f, cancellable, error);
|
||||
if (!in)
|
||||
goto out;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_autofree guchar *csum = NULL;
|
||||
if (!ostree_checksum_file_from_input (f_info, xattrs, in,
|
||||
OSTREE_OBJECT_TYPE_FILE,
|
||||
&csum, cancellable, error))
|
||||
goto out;
|
||||
return FALSE;
|
||||
ret_checksum = ostree_checksum_from_bytes (csum);
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
ot_transfer_out_value(out_checksum, &ret_checksum);
|
||||
out:
|
||||
return ret;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
OstreeDiffItem *
|
||||
@ -130,28 +127,22 @@ diff_files (OstreeDiffFlags flags,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
g_autofree char *checksum_a = NULL;
|
||||
g_autofree char *checksum_b = NULL;
|
||||
OstreeDiffItem *ret_item = NULL;
|
||||
|
||||
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))
|
||||
goto out;
|
||||
return FALSE;
|
||||
|
||||
g_autoptr(OstreeDiffItem) ret_item = NULL;
|
||||
if (strcmp (checksum_a, checksum_b) != 0)
|
||||
{
|
||||
ret_item = diff_item_new (a, a_info, b, b_info,
|
||||
checksum_a, checksum_b);
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
ot_transfer_out_value(out_item, &ret_item);
|
||||
out:
|
||||
if (ret_item)
|
||||
ostree_diff_item_unref (ret_item);
|
||||
return ret;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -160,47 +151,38 @@ diff_add_dir_recurse (GFile *d,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GError *temp_error = NULL;
|
||||
g_autoptr(GFileEnumerator) dir_enum = NULL;
|
||||
g_autoptr(GFile) child = NULL;
|
||||
g_autoptr(GFileInfo) child_info = NULL;
|
||||
|
||||
dir_enum = g_file_enumerate_children (d, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable,
|
||||
error);
|
||||
g_autoptr(GFileEnumerator) dir_enum =
|
||||
g_file_enumerate_children (d, OSTREE_GIO_FAST_QUERYINFO,
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||
cancellable,
|
||||
error);
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
g_clear_object (&child);
|
||||
child = g_file_get_child (d, name);
|
||||
|
||||
g_autoptr(GFile) child = g_file_get_child (d, name);
|
||||
g_ptr_array_add (added, g_object_ref (child));
|
||||
|
||||
if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY)
|
||||
{
|
||||
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;
|
||||
out:
|
||||
return ret;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user