summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-06-28 16:09:37 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2017-06-29 18:17:28 +0000
commitd57410a7e62dcb89321807dcb2d91c85f9d26df7 (patch)
tree02178401c00d3c07b587445df52d4cf6732826c8
parent1a9a473580e9066f5d4a969932d703b5b104b2b7 (diff)
downloadostree-d57410a7e62dcb89321807dcb2d91c85f9d26df7.tar.gz
lib: Add a helper to convert struct stat → GFileInfo
It's more natural for a few calling places. Prep for patches to go the other way, which in turn are prep for adding a commit filter v2 that takes `struct stat`. `ot_gfile_type_for_mode()` was only used in this function, so inline it here. Closes: #974 Approved by: jlebon
-rw-r--r--src/libostree/ostree-core-private.h4
-rw-r--r--src/libostree/ostree-core.c40
-rw-r--r--src/libostree/ostree-repo-commit.c8
-rw-r--r--src/libostree/ostree-repo-libarchive.c29
-rw-r--r--src/libostree/ostree-repo-static-delta-processing.c16
-rw-r--r--src/libostree/ostree-repo.c15
-rw-r--r--src/libotutil/ot-gio-utils.c16
-rw-r--r--src/libotutil/ot-gio-utils.h2
8 files changed, 58 insertions, 72 deletions
diff --git a/src/libostree/ostree-core-private.h b/src/libostree/ostree-core-private.h
index 76c76cc7..799bd228 100644
--- a/src/libostree/ostree-core-private.h
+++ b/src/libostree/ostree-core-private.h
@@ -21,6 +21,7 @@
#pragma once
#include "ostree-core.h"
+#include <sys/stat.h>
G_BEGIN_DECLS
@@ -88,7 +89,8 @@ _ostree_make_temporary_symlink_at (int tmp_dirfd,
GCancellable *cancellable,
GError **error);
-GFileInfo * _ostree_header_gfile_info_new (mode_t mode, uid_t uid, gid_t gid);
+GFileInfo * _ostree_stbuf_to_gfileinfo (const struct stat *stbuf);
+GFileInfo * _ostree_mode_uidgid_to_gfileinfo (mode_t mode, uid_t uid, gid_t gid);
static inline void
_ostree_checksum_inplace_from_bytes_v (GVariant *csum_v, char *buf)
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index c0b7cbe3..6442bd52 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -1493,7 +1493,7 @@ _ostree_loose_path (char *buf,
}
/**
- * _ostree_header_gfile_info_new:
+ * _ostree_stbuf_to_gfileinfo:
* @mode: File mode
* @uid: File uid
* @gid: File gid
@@ -1506,17 +1506,42 @@ _ostree_loose_path (char *buf,
* Returns: (transfer full): A new #GFileInfo mapping a subset of @stbuf.
*/
GFileInfo *
-_ostree_header_gfile_info_new (mode_t mode, uid_t uid, gid_t gid)
+_ostree_stbuf_to_gfileinfo (const struct stat *stbuf)
{
GFileInfo *ret = g_file_info_new ();
- g_file_info_set_attribute_uint32 (ret, "standard::type", ot_gfile_type_for_mode (mode));
+ GFileType ftype;
+ const mode_t mode = stbuf->st_mode;
+ if (S_ISDIR (mode))
+ ftype = G_FILE_TYPE_DIRECTORY;
+ else if (S_ISREG (mode))
+ ftype = G_FILE_TYPE_REGULAR;
+ else if (S_ISLNK (mode))
+ ftype = G_FILE_TYPE_SYMBOLIC_LINK;
+ else if (S_ISBLK (mode) || S_ISCHR(mode) || S_ISFIFO(mode))
+ ftype = G_FILE_TYPE_SPECIAL;
+ else
+ ftype = G_FILE_TYPE_UNKNOWN;
+ g_file_info_set_attribute_uint32 (ret, "standard::type", ftype);
g_file_info_set_attribute_boolean (ret, "standard::is-symlink", S_ISLNK (mode));
- g_file_info_set_attribute_uint32 (ret, "unix::uid", uid);
- g_file_info_set_attribute_uint32 (ret, "unix::gid", gid);
+ g_file_info_set_attribute_uint32 (ret, "unix::uid", stbuf->st_uid);
+ g_file_info_set_attribute_uint32 (ret, "unix::gid", stbuf->st_gid);
g_file_info_set_attribute_uint32 (ret, "unix::mode", mode);
+ if (S_ISREG (mode))
+ g_file_info_set_attribute_uint64 (ret, "standard::size", stbuf->st_size);
+
return ret;
}
+GFileInfo *
+_ostree_mode_uidgid_to_gfileinfo (mode_t mode, uid_t uid, gid_t gid)
+{
+ struct stat stbuf;
+ stbuf.st_mode = mode;
+ stbuf.st_uid = uid;
+ stbuf.st_gid = gid;
+ return _ostree_stbuf_to_gfileinfo (&stbuf);
+}
+
/*
* _ostree_get_relative_object_path:
* @checksum: ASCII checksum string
@@ -1680,8 +1705,7 @@ file_header_parse (GVariant *metadata,
uid = GUINT32_FROM_BE (uid);
gid = GUINT32_FROM_BE (gid);
mode = GUINT32_FROM_BE (mode);
-
- g_autoptr(GFileInfo) ret_file_info = _ostree_header_gfile_info_new (mode, uid, gid);
+ g_autoptr(GFileInfo) ret_file_info = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid);
if (S_ISREG (mode))
{
@@ -1731,7 +1755,7 @@ zlib_file_header_parse (GVariant *metadata,
uid = GUINT32_FROM_BE (uid);
gid = GUINT32_FROM_BE (gid);
mode = GUINT32_FROM_BE (mode);
- g_autoptr(GFileInfo) ret_file_info = _ostree_header_gfile_info_new (mode, uid, gid);
+ g_autoptr(GFileInfo) ret_file_info = _ostree_mode_uidgid_to_gfileinfo (mode, uid, gid);
g_file_info_set_size (ret_file_info, GUINT64_FROM_BE (size));
if (S_ISREG (mode))
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index 45d10163..171fa562 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -2748,7 +2748,7 @@ write_dfd_iter_to_mtree_internal (OstreeRepo *self,
if (fstat (src_dfd_iter->fd, &dir_stbuf) != 0)
return glnx_throw_errno (error);
- child_info = _ostree_header_gfile_info_new (dir_stbuf.st_mode, dir_stbuf.st_uid, dir_stbuf.st_gid);
+ child_info = _ostree_stbuf_to_gfileinfo (&dir_stbuf);
if (modifier != NULL)
{
@@ -2809,13 +2809,11 @@ write_dfd_iter_to_mtree_internal (OstreeRepo *self,
continue;
}
- child_info = _ostree_header_gfile_info_new (stbuf.st_mode, stbuf.st_uid, stbuf.st_gid);
+ child_info = _ostree_stbuf_to_gfileinfo (&stbuf);
g_file_info_set_name (child_info, dent->d_name);
if (S_ISREG (stbuf.st_mode))
- {
- g_file_info_set_size (child_info, stbuf.st_size);
- }
+ ;
else if (S_ISLNK (stbuf.st_mode))
{
if (!ot_readlinkat_gfile_info (src_dfd_iter->fd, dent->d_name,
diff --git a/src/libostree/ostree-repo-libarchive.c b/src/libostree/ostree-repo-libarchive.c
index 1109d5d7..2e1696b5 100644
--- a/src/libostree/ostree-repo-libarchive.c
+++ b/src/libostree/ostree-repo-libarchive.c
@@ -126,33 +126,24 @@ squash_trailing_slashes (char *path)
static GFileInfo *
file_info_from_archive_entry (struct archive_entry *entry)
{
- g_autoptr(GFileInfo) info = NULL;
- const struct stat *st = NULL;
- guint32 file_type;
- mode_t mode;
-
- st = archive_entry_stat (entry);
- mode = st->st_mode;
+ const struct stat *st = archive_entry_stat (entry);
+ struct stat st_copy;
/* Some archives only store the permission mode bits in hardlink entries, so
* let's just make it into a regular file. Yes, this hack will work even if
* it's a hardlink to a symlink. */
if (archive_entry_hardlink (entry))
- mode |= S_IFREG;
-
- info = _ostree_header_gfile_info_new (mode, st->st_uid, st->st_gid);
-
- file_type = ot_gfile_type_for_mode (mode);
- if (file_type == G_FILE_TYPE_REGULAR)
{
- g_file_info_set_attribute_uint64 (info, "standard::size", st->st_size);
- }
- else if (file_type == G_FILE_TYPE_SYMBOLIC_LINK)
- {
- g_file_info_set_attribute_byte_string (info, "standard::symlink-target",
- archive_entry_symlink (entry));
+ st_copy = *st;
+ st_copy.st_mode |= S_IFREG;
+ st = &st_copy;
}
+ g_autoptr(GFileInfo) info = _ostree_stbuf_to_gfileinfo (st);
+ if (S_ISLNK (st->st_mode))
+ g_file_info_set_attribute_byte_string (info, "standard::symlink-target",
+ archive_entry_symlink (entry));
+
return g_steal_pointer (&info);
}
diff --git a/src/libostree/ostree-repo-static-delta-processing.c b/src/libostree/ostree-repo-static-delta-processing.c
index 9141f659..028c700d 100644
--- a/src/libostree/ostree-repo-static-delta-processing.c
+++ b/src/libostree/ostree-repo-static-delta-processing.c
@@ -515,18 +515,15 @@ dispatch_bspatch (OstreeRepo *repo,
static gboolean
handle_untrusted_content_checksum (OstreeRepo *repo,
StaticDeltaExecutionState *state,
- GCancellable *cancellable,
+ GCancellable *cancellable,
GError **error)
{
- g_autoptr(GVariant) header = NULL;
- g_autoptr(GFileInfo) finfo = NULL;
- gsize bytes_written;
-
- finfo = _ostree_header_gfile_info_new (state->mode, state->uid, state->gid);
- header = _ostree_file_header_new (finfo, state->xattrs);
+ g_autoptr(GFileInfo) finfo = _ostree_mode_uidgid_to_gfileinfo (state->mode, state->uid, state->gid);
+ g_autoptr(GVariant) header = _ostree_file_header_new (finfo, state->xattrs);
state->content_checksum = g_checksum_new (G_CHECKSUM_SHA256);
+ gsize bytes_written;
if (!_ostree_write_variant_with_size (NULL, header, 0, &bytes_written, state->content_checksum,
cancellable, error))
return FALSE;
@@ -629,9 +626,8 @@ dispatch_open_splice_and_close (OstreeRepo *repo,
else
{
/* Slower path, for symlinks and unpacking deltas into archive-z2 */
- g_autoptr(GFileInfo) finfo = NULL;
-
- finfo = _ostree_header_gfile_info_new (state->mode, state->uid, state->gid);
+ g_autoptr(GFileInfo) finfo =
+ _ostree_mode_uidgid_to_gfileinfo (state->mode, state->uid, state->gid);
if (S_ISLNK (state->mode))
{
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index a53a056e..8f3a8bd0 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -2791,18 +2791,11 @@ ostree_repo_load_file (OstreeRepo *self,
}
if (out_file_info)
{
- *out_file_info = _ostree_header_gfile_info_new (stbuf.st_mode, stbuf.st_uid, stbuf.st_gid);
- if (S_ISREG (stbuf.st_mode))
- {
- g_file_info_set_size (*out_file_info, stbuf.st_size);
- }
- else if (S_ISLNK (stbuf.st_mode))
- {
- g_file_info_set_size (*out_file_info, 0);
- g_file_info_set_symlink_target (*out_file_info, symlink_target);
- }
+ *out_file_info = _ostree_stbuf_to_gfileinfo (&stbuf);
+ if (S_ISLNK (stbuf.st_mode))
+ g_file_info_set_symlink_target (*out_file_info, symlink_target);
else
- g_assert_not_reached ();
+ g_assert (S_ISREG (stbuf.st_mode));
}
ot_transfer_out_value (out_xattrs, &ret_xattrs);
diff --git a/src/libotutil/ot-gio-utils.c b/src/libotutil/ot-gio-utils.c
index a4b61842..af2abb63 100644
--- a/src/libotutil/ot-gio-utils.c
+++ b/src/libotutil/ot-gio-utils.c
@@ -35,22 +35,6 @@
#define O_BINARY 0
#endif
-GFileType
-ot_gfile_type_for_mode (guint32 mode)
-{
- if (S_ISDIR (mode))
- return G_FILE_TYPE_DIRECTORY;
- else if (S_ISREG (mode))
- return G_FILE_TYPE_REGULAR;
- else if (S_ISLNK (mode))
- return G_FILE_TYPE_SYMBOLIC_LINK;
- else if (S_ISBLK (mode) || S_ISCHR(mode) || S_ISFIFO(mode))
- return G_FILE_TYPE_SPECIAL;
- else
- return G_FILE_TYPE_UNKNOWN;
-}
-
-
GFile *
ot_gfile_resolve_path_printf (GFile *path,
const char *format,
diff --git a/src/libotutil/ot-gio-utils.h b/src/libotutil/ot-gio-utils.h
index 0fd3ddf0..a69b744d 100644
--- a/src/libotutil/ot-gio-utils.h
+++ b/src/libotutil/ot-gio-utils.h
@@ -33,8 +33,6 @@ G_BEGIN_DECLS
#define OSTREE_GIO_FAST_QUERYINFO ("standard::name,standard::type,standard::size,standard::is-symlink,standard::symlink-target," \
"unix::device,unix::inode,unix::mode,unix::uid,unix::gid,unix::rdev")
-GFileType ot_gfile_type_for_mode (guint32 mode);
-
GFile * ot_gfile_resolve_path_printf (GFile *path,
const char *format,
...) G_GNUC_PRINTF(2, 3);