core: Switch to GFile* for unpacking and storing objects
This commit is contained in:
parent
c66474750b
commit
7d63ad5ae8
|
|
@ -673,21 +673,16 @@ splice_and_checksum (GOutputStream *out,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
unpack_meta (const char *path,
|
unpack_meta (GFile *file,
|
||||||
const char *dest_path,
|
GFile *dest_file,
|
||||||
GChecksum **out_checksum,
|
GChecksum **out_checksum,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GFile *file = NULL;
|
|
||||||
GFile *dest_file = NULL;
|
|
||||||
GFileInputStream *in = NULL;
|
GFileInputStream *in = NULL;
|
||||||
GChecksum *ret_checksum = NULL;
|
GChecksum *ret_checksum = NULL;
|
||||||
GFileOutputStream *out = NULL;
|
GFileOutputStream *out = NULL;
|
||||||
|
|
||||||
file = ot_gfile_new_for_path (path);
|
|
||||||
dest_file = ot_gfile_new_for_path (dest_path);
|
|
||||||
|
|
||||||
if (out_checksum)
|
if (out_checksum)
|
||||||
ret_checksum = g_checksum_new (G_CHECKSUM_SHA256);
|
ret_checksum = g_checksum_new (G_CHECKSUM_SHA256);
|
||||||
|
|
||||||
|
|
@ -710,12 +705,8 @@ unpack_meta (const char *path,
|
||||||
*out_checksum = ret_checksum;
|
*out_checksum = ret_checksum;
|
||||||
ret_checksum = NULL;
|
ret_checksum = NULL;
|
||||||
out:
|
out:
|
||||||
if (!ret)
|
|
||||||
(void) unlink (dest_path);
|
|
||||||
if (ret_checksum)
|
if (ret_checksum)
|
||||||
g_checksum_free (ret_checksum);
|
g_checksum_free (ret_checksum);
|
||||||
g_clear_object (&file);
|
|
||||||
g_clear_object (&dest_file);
|
|
||||||
g_clear_object (&in);
|
g_clear_object (&in);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -785,14 +776,12 @@ ostree_parse_packed_file (GFile *file,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
unpack_file (const char *path,
|
unpack_file (GFile *file,
|
||||||
const char *dest_path,
|
GFile *dest_file,
|
||||||
GChecksum **out_checksum,
|
GChecksum **out_checksum,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GFile *file = NULL;
|
|
||||||
GFile *dest_file = NULL;
|
|
||||||
GVariant *metadata = NULL;
|
GVariant *metadata = NULL;
|
||||||
GVariant *xattrs = NULL;
|
GVariant *xattrs = NULL;
|
||||||
GInputStream *in = NULL;
|
GInputStream *in = NULL;
|
||||||
|
|
@ -801,8 +790,9 @@ unpack_file (const char *path,
|
||||||
guint32 version, uid, gid, mode;
|
guint32 version, uid, gid, mode;
|
||||||
guint64 content_len;
|
guint64 content_len;
|
||||||
gsize bytes_read;
|
gsize bytes_read;
|
||||||
|
const char *dest_path;
|
||||||
|
|
||||||
file = ot_gfile_new_for_path (path);
|
dest_path = ot_gfile_get_path_cached (dest_file);
|
||||||
|
|
||||||
if (!ostree_parse_packed_file (file, &metadata, &in, NULL, error))
|
if (!ostree_parse_packed_file (file, &metadata, &in, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -815,8 +805,6 @@ unpack_file (const char *path,
|
||||||
mode = GUINT32_FROM_BE (mode);
|
mode = GUINT32_FROM_BE (mode);
|
||||||
content_len = GUINT64_FROM_BE (content_len);
|
content_len = GUINT64_FROM_BE (content_len);
|
||||||
|
|
||||||
dest_file = ot_gfile_new_for_path (dest_path);
|
|
||||||
|
|
||||||
if (out_checksum)
|
if (out_checksum)
|
||||||
ret_checksum = g_checksum_new (G_CHECKSUM_SHA256);
|
ret_checksum = g_checksum_new (G_CHECKSUM_SHA256);
|
||||||
|
|
||||||
|
|
@ -892,7 +880,7 @@ unpack_file (const char *path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ostree_set_xattrs (file, xattrs, NULL, error))
|
if (!ostree_set_xattrs (dest_file, xattrs, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (ret_checksum)
|
if (ret_checksum)
|
||||||
|
|
@ -910,8 +898,6 @@ unpack_file (const char *path,
|
||||||
(void) unlink (dest_path);
|
(void) unlink (dest_path);
|
||||||
if (ret_checksum)
|
if (ret_checksum)
|
||||||
g_checksum_free (ret_checksum);
|
g_checksum_free (ret_checksum);
|
||||||
g_clear_object (&file);
|
|
||||||
g_clear_object (&dest_file);
|
|
||||||
g_clear_object (&in);
|
g_clear_object (&in);
|
||||||
g_clear_object (&out);
|
g_clear_object (&out);
|
||||||
if (metadata)
|
if (metadata)
|
||||||
|
|
@ -922,16 +908,16 @@ unpack_file (const char *path,
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ostree_unpack_object (const char *path,
|
ostree_unpack_object (GFile *file,
|
||||||
OstreeObjectType objtype,
|
OstreeObjectType objtype,
|
||||||
const char *dest_path,
|
GFile *dest,
|
||||||
GChecksum **out_checksum,
|
GChecksum **out_checksum,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
if (objtype == OSTREE_OBJECT_TYPE_META)
|
if (objtype == OSTREE_OBJECT_TYPE_META)
|
||||||
return unpack_meta (path, dest_path, out_checksum, error);
|
return unpack_meta (file, dest, out_checksum, error);
|
||||||
else
|
else
|
||||||
return unpack_file (path, dest_path, out_checksum, error);
|
return unpack_file (file, dest, out_checksum, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,9 +154,9 @@ gboolean ostree_parse_packed_file (GFile *file,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
gboolean ostree_unpack_object (const char *path,
|
gboolean ostree_unpack_object (GFile *file,
|
||||||
OstreeObjectType objtype,
|
OstreeObjectType objtype,
|
||||||
const char *dest_path,
|
GFile *dest,
|
||||||
GChecksum **out_checksum,
|
GChecksum **out_checksum,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -651,7 +651,7 @@ import_gvariant_object (OstreeRepo *self,
|
||||||
if (!write_gvariant_to_tmp (self, type, variant, &tmp_path, &ret_checksum, error))
|
if (!write_gvariant_to_tmp (self, type, variant, &tmp_path, &ret_checksum, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!ostree_repo_store_object_trusted (self, ot_gfile_get_path_cached (tmp_path),
|
if (!ostree_repo_store_object_trusted (self, tmp_path,
|
||||||
g_checksum_get_string (ret_checksum),
|
g_checksum_get_string (ret_checksum),
|
||||||
OSTREE_OBJECT_TYPE_META,
|
OSTREE_OBJECT_TYPE_META,
|
||||||
FALSE, &did_exist, error))
|
FALSE, &did_exist, error))
|
||||||
|
|
@ -789,7 +789,7 @@ prepare_dir_for_checksum_get_object_path (OstreeRepo *self,
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
link_object_trusted (OstreeRepo *self,
|
link_object_trusted (OstreeRepo *self,
|
||||||
const char *path,
|
GFile *file,
|
||||||
const char *checksum,
|
const char *checksum,
|
||||||
OstreeObjectType objtype,
|
OstreeObjectType objtype,
|
||||||
gboolean overwrite,
|
gboolean overwrite,
|
||||||
|
|
@ -818,7 +818,7 @@ link_object_trusted (OstreeRepo *self,
|
||||||
|
|
||||||
(void) unlink (tmp_dest_path);
|
(void) unlink (tmp_dest_path);
|
||||||
|
|
||||||
if (link (path, tmp_dest_path) < 0
|
if (link (ot_gfile_get_path_cached (file), tmp_dest_path) < 0
|
||||||
|| rename (tmp_dest_path, dest_path) < 0)
|
|| rename (tmp_dest_path, dest_path) < 0)
|
||||||
{
|
{
|
||||||
ot_util_set_error_from_errno (error, errno);
|
ot_util_set_error_from_errno (error, errno);
|
||||||
|
|
@ -840,21 +840,18 @@ link_object_trusted (OstreeRepo *self,
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
archive_file_trusted (OstreeRepo *self,
|
archive_file_trusted (OstreeRepo *self,
|
||||||
const char *path,
|
GFile *file,
|
||||||
const char *checksum,
|
const char *checksum,
|
||||||
OstreeObjectType objtype,
|
OstreeObjectType objtype,
|
||||||
gboolean overwrite,
|
gboolean overwrite,
|
||||||
gboolean *did_exist,
|
gboolean *did_exist,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GFile *infile = NULL;
|
|
||||||
GFileOutputStream *out = NULL;
|
GFileOutputStream *out = NULL;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GFile *dest_file = NULL;
|
GFile *dest_file = NULL;
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
|
|
||||||
infile = ot_gfile_new_for_path (path);
|
|
||||||
|
|
||||||
if (!prepare_dir_for_checksum_get_object_path (self, checksum, objtype, &dest_file, error))
|
if (!prepare_dir_for_checksum_get_object_path (self, checksum, objtype, &dest_file, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -883,7 +880,7 @@ archive_file_trusted (OstreeRepo *self,
|
||||||
|
|
||||||
if (out)
|
if (out)
|
||||||
{
|
{
|
||||||
if (!ostree_pack_object ((GOutputStream*)out, infile, objtype, NULL, error))
|
if (!ostree_pack_object ((GOutputStream*)out, file, objtype, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!g_output_stream_close ((GOutputStream*)out, NULL, error))
|
if (!g_output_stream_close ((GOutputStream*)out, NULL, error))
|
||||||
|
|
@ -893,14 +890,13 @@ archive_file_trusted (OstreeRepo *self,
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
g_clear_object (&dest_file);
|
g_clear_object (&dest_file);
|
||||||
g_clear_object (&infile);
|
|
||||||
g_clear_object (&out);
|
g_clear_object (&out);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ostree_repo_store_object_trusted (OstreeRepo *self,
|
ostree_repo_store_object_trusted (OstreeRepo *self,
|
||||||
const char *path,
|
GFile *file,
|
||||||
const char *checksum,
|
const char *checksum,
|
||||||
OstreeObjectType objtype,
|
OstreeObjectType objtype,
|
||||||
gboolean overwrite,
|
gboolean overwrite,
|
||||||
|
|
@ -909,9 +905,9 @@ ostree_repo_store_object_trusted (OstreeRepo *self,
|
||||||
{
|
{
|
||||||
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
||||||
if (priv->archive && objtype == OSTREE_OBJECT_TYPE_FILE)
|
if (priv->archive && objtype == OSTREE_OBJECT_TYPE_FILE)
|
||||||
return archive_file_trusted (self, path, checksum, objtype, overwrite, did_exist, error);
|
return archive_file_trusted (self, file, checksum, objtype, overwrite, did_exist, error);
|
||||||
else
|
else
|
||||||
return link_object_trusted (self, path, checksum, objtype, overwrite, did_exist, error);
|
return link_object_trusted (self, file, checksum, objtype, overwrite, did_exist, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
@ -924,13 +920,14 @@ ostree_repo_store_packfile (OstreeRepo *self,
|
||||||
{
|
{
|
||||||
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GString *tempfile_path = NULL;
|
|
||||||
GChecksum *checksum = NULL;
|
GChecksum *checksum = NULL;
|
||||||
|
GFile *src = NULL;
|
||||||
|
GFile *tempfile = NULL;
|
||||||
|
|
||||||
tempfile_path = g_string_new (priv->path);
|
src = ot_gfile_new_for_path (path);
|
||||||
g_string_append_printf (tempfile_path, "/tmp-unpack-%s", expected_checksum);
|
tempfile = g_file_get_child (priv->tmp_dir, expected_checksum);
|
||||||
|
|
||||||
if (!ostree_unpack_object (path, objtype, tempfile_path->str, &checksum, error))
|
if (!ostree_unpack_object (src, objtype, tempfile, &checksum, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (strcmp (g_checksum_get_string (checksum), expected_checksum) != 0)
|
if (strcmp (g_checksum_get_string (checksum), expected_checksum) != 0)
|
||||||
|
|
@ -941,7 +938,7 @@ ostree_repo_store_packfile (OstreeRepo *self,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ostree_repo_store_object_trusted (self, tempfile_path ? tempfile_path->str : path,
|
if (!ostree_repo_store_object_trusted (self, tempfile,
|
||||||
expected_checksum,
|
expected_checksum,
|
||||||
objtype,
|
objtype,
|
||||||
FALSE, did_exist, error))
|
FALSE, did_exist, error))
|
||||||
|
|
@ -949,11 +946,10 @@ ostree_repo_store_packfile (OstreeRepo *self,
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
if (tempfile_path)
|
if (tempfile)
|
||||||
{
|
(void) g_file_delete (tempfile, NULL, NULL);
|
||||||
(void) unlink (tempfile_path->str);
|
g_clear_object (&tempfile);
|
||||||
g_string_free (tempfile_path, TRUE);
|
g_clear_object (&src);
|
||||||
}
|
|
||||||
if (checksum)
|
if (checksum)
|
||||||
g_checksum_free (checksum);
|
g_checksum_free (checksum);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -1208,7 +1204,7 @@ add_one_file_to_tree_and_import (OstreeRepo *self,
|
||||||
if (!ostree_checksum_file (f, OSTREE_OBJECT_TYPE_FILE, &checksum, NULL, error))
|
if (!ostree_checksum_file (f, OSTREE_OBJECT_TYPE_FILE, &checksum, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!ostree_repo_store_object_trusted (self, abspath, g_checksum_get_string (checksum),
|
if (!ostree_repo_store_object_trusted (self, f, g_checksum_get_string (checksum),
|
||||||
OSTREE_OBJECT_TYPE_FILE, FALSE, &did_exist, error))
|
OSTREE_OBJECT_TYPE_FILE, FALSE, &did_exist, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -1757,9 +1753,12 @@ checkout_tree (OstreeRepo *self,
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
GFileInfo *file_info = NULL;
|
GFileInfo *file_info = NULL;
|
||||||
GFileEnumerator *dir_enum = NULL;
|
GFileEnumerator *dir_enum = NULL;
|
||||||
|
GFile *destination_f = NULL;
|
||||||
GFile *child = NULL;
|
GFile *child = NULL;
|
||||||
GFile *object_path = NULL;
|
GFile *object_path = NULL;
|
||||||
char *dest_path = NULL;
|
GFile *dest_path = NULL;
|
||||||
|
|
||||||
|
destination_f = ot_gfile_new_for_path (destination);
|
||||||
|
|
||||||
dir_enum = g_file_enumerate_children ((GFile*)dir, OSTREE_GIO_FAST_QUERYINFO,
|
dir_enum = g_file_enumerate_children ((GFile*)dir, OSTREE_GIO_FAST_QUERYINFO,
|
||||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
|
|
@ -1787,17 +1786,17 @@ checkout_tree (OstreeRepo *self,
|
||||||
{
|
{
|
||||||
const char *checksum = _ostree_repo_file_get_checksum ((OstreeRepoFile*)child);
|
const char *checksum = _ostree_repo_file_get_checksum ((OstreeRepoFile*)child);
|
||||||
|
|
||||||
dest_path = g_build_filename (destination, name, NULL);
|
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_unpack_object (ot_gfile_get_path_cached (object_path), OSTREE_OBJECT_TYPE_FILE, dest_path, NULL, error))
|
if (!ostree_unpack_object (object_path, OSTREE_OBJECT_TYPE_FILE, dest_path, NULL, error))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (link (ot_gfile_get_path_cached (object_path), dest_path) < 0)
|
if (link (ot_gfile_get_path_cached (object_path), ot_gfile_get_path_cached (dest_path)) < 0)
|
||||||
{
|
{
|
||||||
ot_util_set_error_from_errno (error, errno);
|
ot_util_set_error_from_errno (error, errno);
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -1806,8 +1805,7 @@ checkout_tree (OstreeRepo *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_object (&object_path);
|
g_clear_object (&object_path);
|
||||||
g_free (dest_path);
|
g_clear_object (&dest_path);
|
||||||
dest_path = NULL;
|
|
||||||
g_clear_object (&file_info);
|
g_clear_object (&file_info);
|
||||||
g_clear_object (&child);
|
g_clear_object (&child);
|
||||||
}
|
}
|
||||||
|
|
@ -1823,6 +1821,8 @@ checkout_tree (OstreeRepo *self,
|
||||||
g_clear_object (&file_info);
|
g_clear_object (&file_info);
|
||||||
g_clear_object (&child);
|
g_clear_object (&child);
|
||||||
g_clear_object (&object_path);
|
g_clear_object (&object_path);
|
||||||
|
g_clear_object (&dest_path);
|
||||||
|
g_clear_object (&destination_f);
|
||||||
g_free (dest_path);
|
g_free (dest_path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ gboolean ostree_repo_store_packfile (OstreeRepo *self,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
gboolean ostree_repo_store_object_trusted (OstreeRepo *self,
|
gboolean ostree_repo_store_object_trusted (OstreeRepo *self,
|
||||||
const char *path,
|
GFile *file,
|
||||||
const char *checksum,
|
const char *checksum,
|
||||||
OstreeObjectType objtype,
|
OstreeObjectType objtype,
|
||||||
gboolean overwrite,
|
gboolean overwrite,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue