core: Deduplicate code converting struct stat -> GFileInfo
We were doing the same thing in a number of places, make a helper function.
This commit is contained in:
parent
880328ba03
commit
c4efbf6718
|
|
@ -81,6 +81,8 @@ _ostree_make_temporary_symlink_at (int tmp_dirfd,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
GFileInfo * _ostree_header_gfile_info_new (mode_t mode, uid_t uid, gid_t gid);
|
||||||
|
|
||||||
/* XX + / + checksum-2 + . + extension, but let's just use 256 for a
|
/* XX + / + checksum-2 + . + extension, but let's just use 256 for a
|
||||||
* bit of overkill.
|
* bit of overkill.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1264,6 +1264,31 @@ _ostree_loose_path (char *buf,
|
||||||
_ostree_loose_path_with_suffix (buf, checksum, objtype, mode, "");
|
_ostree_loose_path_with_suffix (buf, checksum, objtype, mode, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _ostree_header_gfile_info_new:
|
||||||
|
* @mode: File mode
|
||||||
|
* @uid: File uid
|
||||||
|
* @gid: File gid
|
||||||
|
*
|
||||||
|
* OSTree only stores a subset of file attributes; for example,
|
||||||
|
* timestamps are intentionally not stored. This function creates a
|
||||||
|
* #GFileInfo based on the attributes of a `struct stat` that match
|
||||||
|
* those file attributes.
|
||||||
|
*
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
GFileInfo *ret = g_file_info_new ();
|
||||||
|
g_file_info_set_attribute_uint32 (ret, "standard::type", ot_gfile_type_for_mode (mode));
|
||||||
|
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::mode", mode);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* _ostree_loose_path_with_suffix:
|
* _ostree_loose_path_with_suffix:
|
||||||
* @buf: Output buffer, must be _OSTREE_LOOSE_PATH_MAX in size
|
* @buf: Output buffer, must be _OSTREE_LOOSE_PATH_MAX in size
|
||||||
|
|
@ -1367,12 +1392,7 @@ file_header_parse (GVariant *metadata,
|
||||||
mode = GUINT32_FROM_BE (mode);
|
mode = GUINT32_FROM_BE (mode);
|
||||||
rdev = GUINT32_FROM_BE (rdev);
|
rdev = GUINT32_FROM_BE (rdev);
|
||||||
|
|
||||||
ret_file_info = g_file_info_new ();
|
ret_file_info = _ostree_header_gfile_info_new (mode, uid, gid);
|
||||||
g_file_info_set_attribute_uint32 (ret_file_info, "standard::type", ot_gfile_type_for_mode (mode));
|
|
||||||
g_file_info_set_attribute_boolean (ret_file_info, "standard::is-symlink", S_ISLNK (mode));
|
|
||||||
g_file_info_set_attribute_uint32 (ret_file_info, "unix::uid", uid);
|
|
||||||
g_file_info_set_attribute_uint32 (ret_file_info, "unix::gid", gid);
|
|
||||||
g_file_info_set_attribute_uint32 (ret_file_info, "unix::mode", mode);
|
|
||||||
|
|
||||||
if (S_ISREG (mode))
|
if (S_ISREG (mode))
|
||||||
{
|
{
|
||||||
|
|
@ -1423,19 +1443,13 @@ zlib_file_header_parse (GVariant *metadata,
|
||||||
&uid, &gid, &mode, &rdev,
|
&uid, &gid, &mode, &rdev,
|
||||||
&symlink_target, &ret_xattrs);
|
&symlink_target, &ret_xattrs);
|
||||||
|
|
||||||
size = GUINT64_FROM_BE (size);
|
|
||||||
uid = GUINT32_FROM_BE (uid);
|
uid = GUINT32_FROM_BE (uid);
|
||||||
gid = GUINT32_FROM_BE (gid);
|
gid = GUINT32_FROM_BE (gid);
|
||||||
mode = GUINT32_FROM_BE (mode);
|
mode = GUINT32_FROM_BE (mode);
|
||||||
rdev = GUINT32_FROM_BE (rdev);
|
rdev = GUINT32_FROM_BE (rdev);
|
||||||
|
ret_file_info = _ostree_header_gfile_info_new (mode, uid, gid);
|
||||||
|
|
||||||
ret_file_info = g_file_info_new ();
|
g_file_info_set_size (ret_file_info, GUINT64_FROM_BE (size));
|
||||||
g_file_info_set_size (ret_file_info, size);
|
|
||||||
g_file_info_set_attribute_uint32 (ret_file_info, "standard::type", ot_gfile_type_for_mode (mode));
|
|
||||||
g_file_info_set_attribute_boolean (ret_file_info, "standard::is-symlink", S_ISLNK (mode));
|
|
||||||
g_file_info_set_attribute_uint32 (ret_file_info, "unix::uid", uid);
|
|
||||||
g_file_info_set_attribute_uint32 (ret_file_info, "unix::gid", gid);
|
|
||||||
g_file_info_set_attribute_uint32 (ret_file_info, "unix::mode", mode);
|
|
||||||
|
|
||||||
if (S_ISREG (mode))
|
if (S_ISREG (mode))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "ostree-core-private.h"
|
||||||
#include "ostree-repo-private.h"
|
#include "ostree-repo-private.h"
|
||||||
#include "ostree-mutable-tree.h"
|
#include "ostree-mutable-tree.h"
|
||||||
|
|
||||||
|
|
@ -48,19 +49,15 @@ file_info_from_archive_entry_and_modifier (OstreeRepo *repo,
|
||||||
struct archive_entry *entry,
|
struct archive_entry *entry,
|
||||||
OstreeRepoCommitModifier *modifier)
|
OstreeRepoCommitModifier *modifier)
|
||||||
{
|
{
|
||||||
gs_unref_object GFileInfo *info = g_file_info_new ();
|
gs_unref_object GFileInfo *info = NULL;
|
||||||
GFileInfo *modified_info = NULL;
|
GFileInfo *modified_info = NULL;
|
||||||
const struct stat *st;
|
const struct stat *st;
|
||||||
guint32 file_type;
|
guint32 file_type;
|
||||||
|
|
||||||
st = archive_entry_stat (entry);
|
st = archive_entry_stat (entry);
|
||||||
|
|
||||||
|
info = _ostree_header_gfile_info_new (st->st_mode, st->st_uid, st->st_gid);
|
||||||
file_type = ot_gfile_type_for_mode (st->st_mode);
|
file_type = ot_gfile_type_for_mode (st->st_mode);
|
||||||
g_file_info_set_attribute_boolean (info, "standard::is-symlink", S_ISLNK (st->st_mode));
|
|
||||||
g_file_info_set_attribute_uint32 (info, "standard::type", file_type);
|
|
||||||
g_file_info_set_attribute_uint32 (info, "unix::uid", st->st_uid);
|
|
||||||
g_file_info_set_attribute_uint32 (info, "unix::gid", st->st_gid);
|
|
||||||
g_file_info_set_attribute_uint32 (info, "unix::mode", st->st_mode);
|
|
||||||
|
|
||||||
if (file_type == G_FILE_TYPE_REGULAR)
|
if (file_type == G_FILE_TYPE_REGULAR)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1802,11 +1802,10 @@ query_info_for_bare_content_object (OstreeRepo *self,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_info = g_file_info_new ();
|
ret_info = _ostree_header_gfile_info_new (stbuf.st_mode, stbuf.st_uid, stbuf.st_gid);
|
||||||
|
|
||||||
if (S_ISREG (stbuf.st_mode))
|
if (S_ISREG (stbuf.st_mode))
|
||||||
{
|
{
|
||||||
g_file_info_set_file_type (ret_info, G_FILE_TYPE_REGULAR);
|
|
||||||
g_file_info_set_size (ret_info, stbuf.st_size);
|
g_file_info_set_size (ret_info, stbuf.st_size);
|
||||||
}
|
}
|
||||||
else if (S_ISLNK (stbuf.st_mode))
|
else if (S_ISLNK (stbuf.st_mode))
|
||||||
|
|
@ -1814,8 +1813,6 @@ query_info_for_bare_content_object (OstreeRepo *self,
|
||||||
char targetbuf[PATH_MAX+1];
|
char targetbuf[PATH_MAX+1];
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
g_file_info_set_file_type (ret_info, G_FILE_TYPE_SYMBOLIC_LINK);
|
|
||||||
|
|
||||||
do
|
do
|
||||||
len = readlinkat (self->objects_dir_fd, loose_path_buf, targetbuf, sizeof (targetbuf) - 1);
|
len = readlinkat (self->objects_dir_fd, loose_path_buf, targetbuf, sizeof (targetbuf) - 1);
|
||||||
while (G_UNLIKELY (len == -1 && errno == EINTR));
|
while (G_UNLIKELY (len == -1 && errno == EINTR));
|
||||||
|
|
@ -1834,11 +1831,6 @@ query_info_for_bare_content_object (OstreeRepo *self,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_file_info_set_attribute_boolean (ret_info, "standard::is-symlink", S_ISLNK (stbuf.st_mode));
|
|
||||||
g_file_info_set_attribute_uint32 (ret_info, "unix::uid", stbuf.st_uid);
|
|
||||||
g_file_info_set_attribute_uint32 (ret_info, "unix::gid", stbuf.st_gid);
|
|
||||||
g_file_info_set_attribute_uint32 (ret_info, "unix::mode", stbuf.st_mode);
|
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
gs_transfer_out_value (out_info, &ret_info);
|
gs_transfer_out_value (out_info, &ret_info);
|
||||||
out:
|
out:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue