core: Add -U option for checkout to skip lchown() and xattrs
This is useful for checking out an OS filesystem tree as a regular user, and not caring about /dev and stuff.
This commit is contained in:
parent
a94e0b8bf8
commit
d70950e891
|
|
@ -1968,8 +1968,45 @@ ostree_repo_load_variant (OstreeRepo *self,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
checkout_file_from_input (GFile *file,
|
||||||
|
OstreeRepoCheckoutMode mode,
|
||||||
|
GFileInfo *finfo,
|
||||||
|
GVariant *xattrs,
|
||||||
|
GInputStream *input,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
GFileInfo *temp_info = NULL;
|
||||||
|
|
||||||
|
if (mode == OSTREE_REPO_CHECKOUT_MODE_USER)
|
||||||
|
{
|
||||||
|
if (g_file_info_get_file_type (finfo) == G_FILE_TYPE_SPECIAL)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
temp_info = g_file_info_dup (finfo);
|
||||||
|
|
||||||
|
g_file_info_set_attribute_uint32 (temp_info, "unix::uid", geteuid ());
|
||||||
|
g_file_info_set_attribute_uint32 (temp_info, "unix::gid", getegid ());
|
||||||
|
|
||||||
|
xattrs = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ostree_create_file_from_input (file, temp_info ? temp_info : finfo,
|
||||||
|
xattrs, input, OSTREE_OBJECT_TYPE_FILE,
|
||||||
|
NULL, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
g_clear_object (&temp_info);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
checkout_tree (OstreeRepo *self,
|
checkout_tree (OstreeRepo *self,
|
||||||
|
OstreeRepoCheckoutMode mode,
|
||||||
OstreeRepoFile *dir,
|
OstreeRepoFile *dir,
|
||||||
const char *destination,
|
const char *destination,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
@ -1977,6 +2014,7 @@ checkout_tree (OstreeRepo *self,
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
checkout_one_directory (OstreeRepo *self,
|
checkout_one_directory (OstreeRepo *self,
|
||||||
|
OstreeRepoCheckoutMode mode,
|
||||||
const char *destination,
|
const char *destination,
|
||||||
const char *dirname,
|
const char *dirname,
|
||||||
OstreeRepoFile *dir,
|
OstreeRepoFile *dir,
|
||||||
|
|
@ -1995,15 +2033,22 @@ checkout_one_directory (OstreeRepo *self,
|
||||||
if (!_ostree_repo_file_get_xattrs (dir, &xattr_variant, NULL, error))
|
if (!_ostree_repo_file_get_xattrs (dir, &xattr_variant, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!ostree_create_file_from_input (dest_file, dir_info,
|
if (!checkout_file_from_input (dest_file, mode, dir_info,
|
||||||
xattr_variant,
|
xattr_variant,
|
||||||
NULL,
|
NULL,
|
||||||
OSTREE_OBJECT_TYPE_FILE,
|
cancellable, error))
|
||||||
NULL,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!checkout_tree (self, dir, dest_path, cancellable, error))
|
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;
|
goto out;
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
@ -2016,6 +2061,7 @@ checkout_one_directory (OstreeRepo *self,
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
checkout_tree (OstreeRepo *self,
|
checkout_tree (OstreeRepo *self,
|
||||||
|
OstreeRepoCheckoutMode mode,
|
||||||
OstreeRepoFile *dir,
|
OstreeRepoFile *dir,
|
||||||
const char *destination,
|
const char *destination,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
@ -2054,7 +2100,7 @@ checkout_tree (OstreeRepo *self,
|
||||||
|
|
||||||
if (type == G_FILE_TYPE_DIRECTORY)
|
if (type == G_FILE_TYPE_DIRECTORY)
|
||||||
{
|
{
|
||||||
if (!checkout_one_directory (self, destination, name, (OstreeRepoFile*)child, file_info, cancellable, error))
|
if (!checkout_one_directory (self, mode, destination, name, (OstreeRepoFile*)child, file_info, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -2070,11 +2116,8 @@ checkout_tree (OstreeRepo *self,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!ostree_create_file_from_input (dest_path, file_info, packed_xattrs,
|
if (!checkout_file_from_input (dest_path, mode, file_info, packed_xattrs,
|
||||||
packed_input,
|
packed_input, cancellable, error))
|
||||||
OSTREE_OBJECT_TYPE_FILE,
|
|
||||||
NULL,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -2091,6 +2134,8 @@ checkout_tree (OstreeRepo *self,
|
||||||
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 (&child);
|
||||||
|
g_clear_object (&packed_input);
|
||||||
|
ot_clear_gvariant (&packed_xattrs);
|
||||||
}
|
}
|
||||||
if (file_info == NULL && temp_error != NULL)
|
if (file_info == NULL && temp_error != NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -2114,6 +2159,7 @@ checkout_tree (OstreeRepo *self,
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ostree_repo_checkout (OstreeRepo *self,
|
ostree_repo_checkout (OstreeRepo *self,
|
||||||
|
OstreeRepoCheckoutMode mode,
|
||||||
const char *rev,
|
const char *rev,
|
||||||
const char *destination,
|
const char *destination,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
@ -2145,7 +2191,7 @@ ostree_repo_checkout (OstreeRepo *self,
|
||||||
if (!root_info)
|
if (!root_info)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!checkout_one_directory (self, destination, NULL, root, root_info, cancellable, error))
|
if (!checkout_one_directory (self, mode, destination, NULL, root, root_info, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,13 @@ gboolean ostree_repo_commit_tarfile (OstreeRepo *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
OSTREE_REPO_CHECKOUT_MODE_NONE,
|
||||||
|
OSTREE_REPO_CHECKOUT_MODE_USER
|
||||||
|
} OstreeRepoCheckoutMode;
|
||||||
|
|
||||||
gboolean ostree_repo_checkout (OstreeRepo *self,
|
gboolean ostree_repo_checkout (OstreeRepo *self,
|
||||||
|
OstreeRepoCheckoutMode mode,
|
||||||
const char *ref,
|
const char *ref,
|
||||||
const char *destination,
|
const char *destination,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,10 @@
|
||||||
|
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
|
static gboolean user_mode;
|
||||||
|
|
||||||
static GOptionEntry options[] = {
|
static GOptionEntry options[] = {
|
||||||
|
{ "user-mode", 'U', 0, G_OPTION_ARG_NONE, &user_mode, "Do not change file ownership or initialze extended attributes", NULL },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -65,7 +68,8 @@ ostree_builtin_checkout (int argc, char **argv, const char *repo_path, GError **
|
||||||
commit = argv[1];
|
commit = argv[1];
|
||||||
destination = argv[2];
|
destination = argv[2];
|
||||||
|
|
||||||
if (!ostree_repo_checkout (repo, commit, destination, NULL, error))
|
if (!ostree_repo_checkout (repo, user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0,
|
||||||
|
commit, destination, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,8 @@ compose_branch_on_dir (OstreeRepo *repo,
|
||||||
branchf = ot_gfile_new_for_path (branchpath);
|
branchf = ot_gfile_new_for_path (branchpath);
|
||||||
|
|
||||||
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, branchrev, branchpath, NULL, error))
|
if (!ostree_repo_checkout (repo, OSTREE_REPO_CHECKOUT_MODE_NONE,
|
||||||
|
branchrev, branchpath, 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