New upstream version 2021.2

This commit is contained in:
Simon McVittie committed 2021-04-17 00:55:26 +01:00
commit 3b95643e80
41 files changed
+1625 -406

No files matched your search

+2 -2
View File
@@ -26,8 +26,8 @@
* edit this other than to update the year. This is just a copy/paste
* source. Replace $LASTSTABLE with the last stable version, and $NEWVERSION
* with whatever the next version with new symbols will be.
LIBOSTREE_2020.$NEWVERSION {
LIBOSTREE_2021.$NEWVERSION {
global:
someostree_symbol_deleteme;
} LIBOSTREE_2020.$LASTSTABLE;
} LIBOSTREE_2021.$LASTSTABLE;
*/
+9
View File
@@ -644,6 +644,15 @@ global:
ostree_sysroot_require_booted_deployment;
} LIBOSTREE_2020.8;
LIBOSTREE_2021.2 {
global:
ostree_repo_write_regfile_inline;
ostree_repo_write_symlink;
ostree_repo_write_regfile;
ostree_content_writer_get_type;
ostree_content_writer_finish;
} LIBOSTREE_2021.1;
/* NOTE: Only add more content here in release commits! See the
* comments at the top of this file.
*/
+144
View File
@@ -0,0 +1,144 @@
/*
* SPDX-License-Identifier: LGPL-2.0+
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "ostree-content-writer.h"
#include "ostree-repo-private.h"
#include "ostree-autocleanups.h"
struct _OstreeContentWriter
{
GOutputStream parent_instance;
OstreeRepo *repo;
OstreeRepoBareContent output;
};
G_DEFINE_TYPE (OstreeContentWriter, ostree_content_writer, G_TYPE_OUTPUT_STREAM)
static void ostree_content_writer_finalize (GObject *object);
static gssize ostree_content_writer_write (GOutputStream *stream,
const void *buffer,
gsize count,
GCancellable *cancellable,
GError **error);
static gboolean ostree_content_writer_close (GOutputStream *stream,
GCancellable *cancellable,
GError **error);
static void
ostree_content_writer_class_init (OstreeContentWriterClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GOutputStreamClass *stream_class = G_OUTPUT_STREAM_CLASS (klass);
gobject_class->finalize = ostree_content_writer_finalize;
stream_class->write_fn = ostree_content_writer_write;
stream_class->close_fn = ostree_content_writer_close;
}
static void
ostree_content_writer_finalize (GObject *object)
{
OstreeContentWriter *stream;
stream = (OstreeContentWriter*)(object);
g_clear_object (&stream->repo);
_ostree_repo_bare_content_cleanup (&stream->output);
G_OBJECT_CLASS (ostree_content_writer_parent_class)->finalize (object);
}
static void
ostree_content_writer_init (OstreeContentWriter *self)
{
self->output.initialized = FALSE;
}
OstreeContentWriter *
_ostree_content_writer_new (OstreeRepo *repo,
const char *checksum,
guint uid,
guint gid,
guint mode,
guint64 content_len,
GVariant *xattrs,
GError **error)
{
g_autoptr(OstreeContentWriter) stream = g_object_new (OSTREE_TYPE_CONTENT_WRITER, NULL);
stream->repo = g_object_ref (repo);
if (!_ostree_repo_bare_content_open (stream->repo, checksum, content_len, uid, gid, mode, xattrs,
&stream->output, NULL, error))
return NULL;
return g_steal_pointer (&stream);
}
static gssize
ostree_content_writer_write (GOutputStream *stream,
const void *buffer,
gsize count,
GCancellable *cancellable,
GError **error)
{
OstreeContentWriter *self = (OstreeContentWriter*) stream;
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return -1;
if (!_ostree_repo_bare_content_write (self->repo, &self->output,
buffer, count, cancellable, error))
return -1;
return count;
}
static gboolean
ostree_content_writer_close (GOutputStream *stream,
GCancellable *cancellable,
GError **error)
{
/* We don't expect people to invoke close() - they need to call finish()
* to get the checksum. We'll clean up in finalize anyways if need be.
*/
return TRUE;
}
/**
* ostree_content_writer_finish:
* @self: Writer
* @cancellable: Cancellable
* @error: Error
*
* Complete the object write and return the checksum.
* Returns: (transfer full): Checksum, or %NULL on error
*/
char *
ostree_content_writer_finish (OstreeContentWriter *self,
GCancellable *cancellable,
GError **error)
{
char actual_checksum[OSTREE_SHA256_STRING_LEN+1];
if (!_ostree_repo_bare_content_commit (self->repo, &self->output, actual_checksum,
sizeof (actual_checksum), cancellable, error))
return NULL;
return g_strdup (actual_checksum);
}
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2021 Red Hat, Inc.
*
* SPDX-License-Identifier: LGPL-2.0+
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#pragma once
#include <gio/gio.h>
G_BEGIN_DECLS
#define OSTREE_TYPE_CONTENT_WRITER (ostree_content_writer_get_type ())
_OSTREE_PUBLIC G_DECLARE_FINAL_TYPE (OstreeContentWriter, ostree_content_writer, OSTREE, CONTENT_WRITER, GOutputStream)
_OSTREE_PUBLIC
char * ostree_content_writer_finish (OstreeContentWriter *self,
GCancellable *cancellable,
GError **error);
G_END_DECLS
+15 -38
View File
@@ -391,24 +391,18 @@ variant_to_lenprefixed_buffer (GVariant *variant)
const guint32 variant_size_u32_be = GUINT32_TO_BE((guint32) variant_size);
g_string_append_len (buf, (char*)&variant_size_u32_be, sizeof (variant_size_u32_be));
const gsize alignment_offset = sizeof (variant_size_u32_be);
/* Write NULs for alignment. At the moment this is a constant 4 bytes (i.e.
* align to 8, since the length is 4 bytes). For now, I decided to keep some
* of the (now legacy) more generic logic here in case we want to revive it
* later.
* align to 8, since the length is 4 bytes). If we ever change this, the
* logic is here:
*/
const guint alignment = 8;
const guchar padding_nuls[8] = {0, 0, 0, 0, 0, 0, 0, 0};
guint bits;
if (alignment == 8)
bits = alignment_offset & 7; /* mod 8 */
else
bits = alignment_offset & 3; /* mod 4 */
const guint padding_len = alignment - bits;
if (bits > 0)
g_string_append_len (buf, (char*)padding_nuls, padding_len);
// const gsize alignment_offset = sizeof (variant_size_u32_be);
// const guint bits = alignment_offset & 7; /* mod 8 */
// const guint padding_len = alignment - bits;
#define padding_len sizeof(guint32)
const guchar padding_nuls[padding_len] = {0, 0, 0, 0};
g_string_append_len (buf, (char*)padding_nuls, padding_len);
#undef padding_len
g_string_append_len (buf, (char*)g_variant_get_data (variant), g_variant_get_size (variant));
return g_string_free_to_bytes (g_steal_pointer (&buf));
@@ -418,18 +412,12 @@ variant_to_lenprefixed_buffer (GVariant *variant)
* header_and_input_to_stream:
* @file_header: A file header
* @input: File raw content stream
* @out_input: (out): Serialized object stream
* @cancellable: Cancellable
* @error: Error
*
* Combines @file_header and @input into a single stream.
*/
static gboolean
static GInputStream *
header_and_input_to_stream (GBytes *file_header,
GInputStream *input,
GInputStream **out_input,
GCancellable *cancellable,
GError **error)
GInputStream *input)
{
/* Our result stream chain */
g_autoptr(GPtrArray) streams = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
@@ -444,10 +432,7 @@ header_and_input_to_stream (GBytes *file_header,
g_ptr_array_add (streams, g_object_ref (input));
/* Return the result stream */
g_autoptr(GInputStream) ret_input = (GInputStream*)ostree_chain_input_stream_new (streams);
ot_transfer_out_value (out_input, &ret_input);
return TRUE;
return (GInputStream*)ostree_chain_input_stream_new (streams);
}
/* Convert file metadata + file content into an archive-format stream. */
@@ -468,11 +453,8 @@ _ostree_raw_file_to_archive_stream (GInputStream *input,
zlib_input = g_converter_input_stream_new (input, zlib_compressor);
}
g_autoptr(GBytes) file_header = _ostree_zlib_file_header_new (file_info, xattrs);
return header_and_input_to_stream (file_header,
zlib_input,
out_input,
cancellable,
error);
*out_input = header_and_input_to_stream (file_header, zlib_input);
return TRUE;
}
/**
@@ -566,12 +548,7 @@ ostree_raw_file_to_content_stream (GInputStream *input,
GError **error)
{
g_autoptr(GBytes) file_header = _ostree_file_header_new (file_info, xattrs);
if (!header_and_input_to_stream (file_header,
input,
out_input,
cancellable,
error))
return FALSE;
*out_input = header_and_input_to_stream (file_header, input);
if (out_length)
*out_length = g_bytes_get_size (file_header) + g_file_info_get_size (file_info);
return TRUE;
+120
View File
@@ -2769,6 +2769,126 @@ ostree_repo_write_content (OstreeRepo *self,
cancellable, error);
}
/**
* ostree_repo_write_regfile_inline:
* @self: repo
* @expected_checksum: (allow-none): The expected checksum
* @uid: User id
* @gid: Group id
* @mode: File mode
* @xattrs: (allow-none): Extended attributes, GVariant of type (ayay)
* @buf: (array length=len) (element-type guint8): File contents
* @cancellable: Cancellable
* @error: Error
*
* Synchronously create a file object from the provided content. This API
* is intended for small files where it is reasonable to buffer the entire
* content in memory.
*
* Unlike `ostree_repo_write_content()`, if @expected_checksum is provided,
* this function will not check for the presence of the object beforehand.
*
* Returns: (transfer full): Checksum (as a hex string) of the committed file
* Since: 2021.2
*/
_OSTREE_PUBLIC
char *
ostree_repo_write_regfile_inline (OstreeRepo *self,
const char *expected_checksum,
guint32 uid,
guint32 gid,
guint32 mode,
GVariant *xattrs,
const guint8* buf,
gsize len,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GInputStream) memin = g_memory_input_stream_new_from_data (buf, len, NULL);
g_autoptr(GFileInfo) finfo = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid);
g_file_info_set_size (finfo, len);
g_autofree guint8* csum = NULL;
if (!write_content_object (self, expected_checksum,
memin, finfo, xattrs, &csum,
cancellable, error))
return NULL;
return ostree_checksum_from_bytes (csum);
}
/**
* ostree_repo_write_symlink:
* @self: repo
* @expected_checksum: (allow-none): The expected checksum
* @uid: User id
* @gid: Group id
* @xattrs: (allow-none): Extended attributes, GVariant of type (ayay)
* @symlink_target: Target of the symbolic link
* @cancellable: Cancellable
* @error: Error
*
* Synchronously create a symlink object.
*
* Unlike `ostree_repo_write_content()`, if @expected_checksum is provided,
* this function will not check for the presence of the object beforehand.
*
* Returns: (transfer full): Checksum (as a hex string) of the committed file
* Since: 2021.2
*/
char *
ostree_repo_write_symlink (OstreeRepo *self,
const char *expected_checksum,
guint32 uid,
guint32 gid,
GVariant *xattrs,
const char *symlink_target,
GCancellable *cancellable,
GError **error)
{
g_assert (symlink_target != NULL);
g_autoptr(GFileInfo) finfo = _ostree_mode_uidgid_to_gfileinfo (S_IFLNK | 0777, uid, gid);
g_file_info_set_attribute_byte_string (finfo, "standard::symlink-target", symlink_target);
g_autofree guint8* csum = NULL;
if (!write_content_object (self, expected_checksum,
NULL, finfo, xattrs, &csum,
cancellable, error))
return NULL;
return ostree_checksum_from_bytes (csum);
}
/**
* ostree_repo_write_regfile:
* @self: Repo,
* @expected_checksum: (allow-none): Expected checksum (SHA-256 hex string)
* @uid: user id
* @gid: group id
* @mode: Unix file mode
* @content_len: Expected content length
* @xattrs: (allow-none): Extended attributes (GVariant type `(ayay)`)
* @error: Error
*
* Create an `OstreeContentWriter` that allows streaming output into
* the repository.
*
* Returns: (transfer full): A new writer, or %NULL on error
* Since: 2021.2
*/
OstreeContentWriter *
ostree_repo_write_regfile (OstreeRepo *self,
const char *expected_checksum,
guint32 uid,
guint32 gid,
guint32 mode,
guint64 content_len,
GVariant *xattrs,
GError **error)
{
if (self->mode == OSTREE_REPO_MODE_ARCHIVE)
return glnx_null_throw (error, "Cannot currently use ostree_repo_write_regfile() on an archive mode repository");
return _ostree_content_writer_new (self, expected_checksum, uid, gid, mode, content_len, xattrs, error);
}
typedef struct {
OstreeRepo *repo;
char *expected_checksum;
+10
View File
@@ -462,6 +462,16 @@ _ostree_repo_bare_content_commit (OstreeRepo *self,
GCancellable *cancellable,
GError **error);
OstreeContentWriter *
_ostree_content_writer_new (OstreeRepo *repo,
const char *checksum,
guint uid,
guint gid,
guint mode,
guint64 content_len,
GVariant *xattrs,
GError **error);
gboolean
_ostree_repo_load_file_bare (OstreeRepo *self,
const char *checksum,
@@ -178,7 +178,7 @@ ostree_repo_list_static_delta_names (OstreeRepo *self,
* This function synchronously enumerates all static delta indexes in the
* repository, returning its result in @out_indexes.
*
* Since: 2020.7
* Since: 2020.8
*/
gboolean
ostree_repo_list_static_delta_indexes (OstreeRepo *self,
@@ -1254,6 +1254,8 @@ file_has_content (OstreeRepo *repo,
* This is normally called automatically when the summary is updated in ostree_repo_regenerate_summary().
*
* Locking: shared
*
* Since: 2020.8
*/
gboolean
ostree_repo_static_delta_reindex (OstreeRepo *repo,
+7 -2
View File
@@ -3686,6 +3686,10 @@ load_metadata_internal (OstreeRepo *self,
g_return_val_if_fail (OSTREE_OBJECT_TYPE_IS_META (objtype), FALSE);
g_return_val_if_fail (objtype == OSTREE_OBJECT_TYPE_COMMIT || out_state == NULL, FALSE);
/* Ensure this is set to NULL if we didn't find the object */
if (out_variant)
*out_variant = NULL;
/* Special caching for dirmeta objects, since they're commonly referenced many
* times.
*/
@@ -4452,12 +4456,13 @@ ostree_repo_query_object_storage_size (OstreeRepo *self,
* @self: Repo
* @objtype: Object type
* @sha256: ASCII checksum
* @out_variant: (out) (transfer full): Metadata
* @out_variant: (out) (nullable) (transfer full): Metadata
* @error: Error
*
* Attempt to load the metadata object @sha256 of type @objtype if it
* exists, storing the result in @out_variant. If it doesn't exist,
* %NULL is returned.
* @out_variant will be set to %NULL and the function will still
* return TRUE.
*/
gboolean
ostree_repo_load_variant_if_exists (OstreeRepo *self,
+32
View File
@@ -423,6 +423,38 @@ gboolean ostree_repo_write_content (OstreeRepo *self,
GCancellable *cancellable,
GError **error);
_OSTREE_PUBLIC
char * ostree_repo_write_regfile_inline (OstreeRepo *self,
const char *expected_checksum,
guint32 uid,
guint32 gid,
guint32 mode,
GVariant *xattrs,
const guint8* buf,
gsize len,
GCancellable *cancellable,
GError **error);
_OSTREE_PUBLIC
OstreeContentWriter * ostree_repo_write_regfile (OstreeRepo *self,
const char *expected_checksum,
guint32 uid,
guint32 gid,
guint32 mode,
guint64 content_len,
GVariant *xattrs,
GError **error);
_OSTREE_PUBLIC
char * ostree_repo_write_symlink (OstreeRepo *self,
const char *expected_checksum,
guint32 uid,
guint32 gid,
GVariant *xattrs,
const char *symlink_target,
GCancellable *cancellable,
GError **error);
_OSTREE_PUBLIC
gboolean ostree_repo_write_metadata_trusted (OstreeRepo *self,
OstreeObjectType objtype,
+1
View File
@@ -38,6 +38,7 @@ typedef struct OstreeSysroot OstreeSysroot;
typedef struct OstreeSysrootUpgrader OstreeSysrootUpgrader;
typedef struct OstreeMutableTree OstreeMutableTree;
typedef struct OstreeRepoFile OstreeRepoFile;
typedef struct _OstreeContentWriter OstreeContentWriter;
typedef struct OstreeRemote OstreeRemote;
G_END_DECLS
+4 -4
View File
@@ -43,7 +43,7 @@
*
* Since: 2017.4
*/
#define OSTREE_RELEASE_VERSION (1)
#define OSTREE_RELEASE_VERSION (2)
/**
* OSTREE_VERSION
@@ -52,7 +52,7 @@
*
* Since: 2017.4
*/
#define OSTREE_VERSION (2021.1)
#define OSTREE_VERSION (2021.2)
/**
* OSTREE_VERSION_S:
@@ -62,7 +62,7 @@
*
* Since: 2017.4
*/
#define OSTREE_VERSION_S "2021.1"
#define OSTREE_VERSION_S "2021.2"
#define OSTREE_ENCODE_VERSION(year,release) \
((year) << 16 | (release))
@@ -100,4 +100,4 @@
*
* Since: 2019.3
*/
#define OSTREE_BUILT_FEATURES "libsoup gpgme ex-fsverity libarchive selinux libmount systemd release p2p"
#define OSTREE_BUILT_FEATURES "libcurl libsoup gpgme ex-fsverity libarchive selinux openssl libmount systemd release p2p"