core: Clean up checkout code
Take a GFile * for destination. Also, we only need one recursive function, not two.
This commit is contained in:
parent
15d23546ff
commit
dccd106731
|
|
@ -2005,83 +2005,36 @@ checkout_file_from_input (GFile *file,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
checkout_tree (OstreeRepo *self,
|
checkout_tree (OstreeRepo *self,
|
||||||
OstreeRepoCheckoutMode mode,
|
OstreeRepoCheckoutMode mode,
|
||||||
OstreeRepoFile *dir,
|
GFile *destination,
|
||||||
const char *destination,
|
OstreeRepoFile *source,
|
||||||
GCancellable *cancellable,
|
GFileInfo *source_info,
|
||||||
GError **error);
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
static gboolean
|
|
||||||
checkout_one_directory (OstreeRepo *self,
|
|
||||||
OstreeRepoCheckoutMode mode,
|
|
||||||
const char *destination,
|
|
||||||
const char *dirname,
|
|
||||||
OstreeRepoFile *dir,
|
|
||||||
GFileInfo *dir_info,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
GFile *dest_file = NULL;
|
|
||||||
char *dest_path = NULL;
|
|
||||||
GVariant *xattr_variant = NULL;
|
|
||||||
|
|
||||||
dest_path = g_build_filename (destination, dirname, NULL);
|
|
||||||
dest_file = ot_gfile_new_for_path (dest_path);
|
|
||||||
|
|
||||||
if (!_ostree_repo_file_get_xattrs (dir, &xattr_variant, NULL, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (!checkout_file_from_input (dest_file, mode, dir_info,
|
|
||||||
xattr_variant,
|
|
||||||
NULL,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (mode != OSTREE_REPO_CHECKOUT_MODE_USER)
|
|
||||||
{
|
|
||||||
if (!_ostree_repo_file_get_xattrs (dir, &xattr_variant, NULL, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (!ostree_set_xattrs (dest_file, xattr_variant, cancellable, error))
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!checkout_tree (self, mode, dir, dest_path, cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
out:
|
|
||||||
g_clear_object (&dest_file);
|
|
||||||
g_free (dest_path);
|
|
||||||
ot_clear_gvariant (&xattr_variant);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
checkout_tree (OstreeRepo *self,
|
|
||||||
OstreeRepoCheckoutMode mode,
|
|
||||||
OstreeRepoFile *dir,
|
|
||||||
const char *destination,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
{
|
||||||
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
GFileInfo *file_info = NULL;
|
GFileInfo *file_info = NULL;
|
||||||
GInputStream *packed_input = NULL;
|
GInputStream *packed_input = NULL;
|
||||||
GVariant *packed_xattrs = NULL;
|
GVariant *xattrs = NULL;
|
||||||
GFileEnumerator *dir_enum = NULL;
|
GFileEnumerator *dir_enum = NULL;
|
||||||
GFile *destination_f = NULL;
|
GFile *src_child = NULL;
|
||||||
GFile *child = NULL;
|
|
||||||
GFile *object_path = NULL;
|
|
||||||
GFile *dest_path = NULL;
|
GFile *dest_path = NULL;
|
||||||
|
GFile *object_path = NULL;
|
||||||
|
|
||||||
destination_f = ot_gfile_new_for_path (destination);
|
if (!_ostree_repo_file_get_xattrs (source, &xattrs, NULL, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
dir_enum = g_file_enumerate_children ((GFile*)dir, OSTREE_GIO_FAST_QUERYINFO,
|
if (!checkout_file_from_input (destination, mode, source_info,
|
||||||
|
xattrs, NULL,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ot_clear_gvariant (&xattrs);
|
||||||
|
|
||||||
|
dir_enum = g_file_enumerate_children ((GFile*)source, OSTREE_GIO_FAST_QUERYINFO,
|
||||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
cancellable,
|
cancellable,
|
||||||
error);
|
error);
|
||||||
|
|
@ -2096,27 +2049,27 @@ checkout_tree (OstreeRepo *self,
|
||||||
name = g_file_info_get_attribute_byte_string (file_info, "standard::name");
|
name = g_file_info_get_attribute_byte_string (file_info, "standard::name");
|
||||||
type = g_file_info_get_attribute_uint32 (file_info, "standard::type");
|
type = g_file_info_get_attribute_uint32 (file_info, "standard::type");
|
||||||
|
|
||||||
child = g_file_get_child ((GFile*)dir, name);
|
dest_path = g_file_get_child (destination, name);
|
||||||
|
src_child = g_file_get_child ((GFile*)source, name);
|
||||||
|
|
||||||
if (type == G_FILE_TYPE_DIRECTORY)
|
if (type == G_FILE_TYPE_DIRECTORY)
|
||||||
{
|
{
|
||||||
if (!checkout_one_directory (self, mode, destination, name, (OstreeRepoFile*)child, file_info, cancellable, error))
|
if (!checkout_tree (self, mode, dest_path, (OstreeRepoFile*)src_child, file_info, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char *checksum = _ostree_repo_file_get_checksum ((OstreeRepoFile*)child);
|
const char *checksum = _ostree_repo_file_get_checksum ((OstreeRepoFile*)src_child);
|
||||||
|
|
||||||
dest_path = g_file_get_child (destination_f, name);
|
|
||||||
object_path = ostree_repo_get_object_path (self, checksum, OSTREE_OBJECT_TYPE_FILE);
|
object_path = ostree_repo_get_object_path (self, checksum, OSTREE_OBJECT_TYPE_FILE);
|
||||||
|
|
||||||
if (priv->archive)
|
if (priv->archive)
|
||||||
{
|
{
|
||||||
if (!ostree_parse_packed_file (object_path, NULL, &packed_xattrs, &packed_input,
|
if (!ostree_parse_packed_file (object_path, NULL, &xattrs, &packed_input,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!checkout_file_from_input (dest_path, mode, file_info, packed_xattrs,
|
if (!checkout_file_from_input (dest_path, mode, file_info, xattrs,
|
||||||
packed_input, cancellable, error))
|
packed_input, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
@ -2133,9 +2086,9 @@ checkout_tree (OstreeRepo *self,
|
||||||
g_clear_object (&object_path);
|
g_clear_object (&object_path);
|
||||||
g_clear_object (&dest_path);
|
g_clear_object (&dest_path);
|
||||||
g_clear_object (&file_info);
|
g_clear_object (&file_info);
|
||||||
g_clear_object (&child);
|
g_clear_object (&src_child);
|
||||||
g_clear_object (&packed_input);
|
g_clear_object (&packed_input);
|
||||||
ot_clear_gvariant (&packed_xattrs);
|
ot_clear_gvariant (&xattrs);
|
||||||
}
|
}
|
||||||
if (file_info == NULL && temp_error != NULL)
|
if (file_info == NULL && temp_error != NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -2148,37 +2101,28 @@ checkout_tree (OstreeRepo *self,
|
||||||
g_clear_object (&dir_enum);
|
g_clear_object (&dir_enum);
|
||||||
g_clear_object (&file_info);
|
g_clear_object (&file_info);
|
||||||
g_clear_object (&packed_input);
|
g_clear_object (&packed_input);
|
||||||
ot_clear_gvariant (&packed_xattrs);
|
ot_clear_gvariant (&xattrs);
|
||||||
g_clear_object (&child);
|
g_clear_object (&src_child);
|
||||||
g_clear_object (&object_path);
|
g_clear_object (&object_path);
|
||||||
g_clear_object (&dest_path);
|
g_clear_object (&dest_path);
|
||||||
g_clear_object (&destination_f);
|
|
||||||
g_free (dest_path);
|
g_free (dest_path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ostree_repo_checkout (OstreeRepo *self,
|
ostree_repo_checkout (OstreeRepo *self,
|
||||||
OstreeRepoCheckoutMode mode,
|
OstreeRepoCheckoutMode mode,
|
||||||
const char *rev,
|
const char *ref,
|
||||||
const char *destination,
|
GFile *destination,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
char *resolved = NULL;
|
char *resolved = NULL;
|
||||||
OstreeRepoFile *root = NULL;
|
OstreeRepoFile *root = NULL;
|
||||||
GFileInfo *root_info = NULL;
|
GFileInfo *root_info = NULL;
|
||||||
|
|
||||||
if (g_file_test (destination, G_FILE_TEST_EXISTS))
|
if (!ostree_repo_resolve_rev (self, ref, FALSE, &resolved, error))
|
||||||
{
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
||||||
"Destination path '%s' already exists",
|
|
||||||
destination);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ostree_repo_resolve_rev (self, rev, FALSE, &resolved, error))
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
root = (OstreeRepoFile*)_ostree_repo_file_new_root (self, resolved);
|
root = (OstreeRepoFile*)_ostree_repo_file_new_root (self, resolved);
|
||||||
|
|
@ -2191,7 +2135,7 @@ ostree_repo_checkout (OstreeRepo *self,
|
||||||
if (!root_info)
|
if (!root_info)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!checkout_one_directory (self, mode, destination, NULL, root, root_info, cancellable, error))
|
if (!checkout_tree (self, mode, destination, root, root_info, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
|
||||||
|
|
@ -136,12 +136,12 @@ typedef enum {
|
||||||
OSTREE_REPO_CHECKOUT_MODE_USER
|
OSTREE_REPO_CHECKOUT_MODE_USER
|
||||||
} OstreeRepoCheckoutMode;
|
} OstreeRepoCheckoutMode;
|
||||||
|
|
||||||
gboolean ostree_repo_checkout (OstreeRepo *self,
|
gboolean ostree_repo_checkout (OstreeRepo *self,
|
||||||
OstreeRepoCheckoutMode mode,
|
OstreeRepoCheckoutMode mode,
|
||||||
const char *ref,
|
const char *ref,
|
||||||
const char *destination,
|
GFile *destination,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
gboolean ostree_repo_read_commit (OstreeRepo *self,
|
gboolean ostree_repo_read_commit (OstreeRepo *self,
|
||||||
const char *rev,
|
const char *rev,
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,11 @@ ostree_builtin_checkout (int argc, char **argv, const char *repo_path, GError **
|
||||||
|
|
||||||
commit = argv[1];
|
commit = argv[1];
|
||||||
destination = argv[2];
|
destination = argv[2];
|
||||||
|
|
||||||
|
destf = ot_gfile_new_for_path (destination);
|
||||||
|
|
||||||
if (!ostree_repo_checkout (repo, user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0,
|
if (!ostree_repo_checkout (repo, user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0,
|
||||||
commit, destination, NULL, error))
|
commit, destf, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ compose_branch_on_dir (OstreeRepo *repo,
|
||||||
|
|
||||||
g_print ("Checking out %s (commit %s)...\n", branch, branchrev);
|
g_print ("Checking out %s (commit %s)...\n", branch, branchrev);
|
||||||
if (!ostree_repo_checkout (repo, OSTREE_REPO_CHECKOUT_MODE_NONE,
|
if (!ostree_repo_checkout (repo, OSTREE_REPO_CHECKOUT_MODE_NONE,
|
||||||
branchrev, branchpath, NULL, error))
|
branchrev, branchf, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
g_print ("...done\n");
|
g_print ("...done\n");
|
||||||
g_print ("Merging over destination...\n");
|
g_print ("Merging over destination...\n");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue