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
This commit is contained in:
1 parent
1a9a473580
commit
d57410a7e6
8 files changed
+58
-72
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user