Skip to content

Commit

Permalink
repo: Improve ostree_repo_load_file() to use *at() for xattrs
Browse files Browse the repository at this point in the history
We were already using openat() for the contents, but not the xattrs.
Now that libgsystem 2014.3 has gs_fd_get_all_xattrs(), make use of it.

Clean things up a bit so we only open the fd once.
  • Loading branch information
cgwalters committed Jan 6, 2015
1 parent 6dab41b commit 86764db
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/libostree/ostree-repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1972,26 +1972,37 @@ ostree_repo_load_file (OstreeRepo *self,
}
}

if (repo_mode == OSTREE_REPO_MODE_BARE)
g_assert (repo_mode == OSTREE_REPO_MODE_BARE);

if (g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_REGULAR
&& (out_input || out_xattrs))
{
gs_fd_close int fd = -1;

if (!gs_file_openat_noatime (self->objects_dir_fd, loose_path_buf, &fd,
cancellable, error))
goto out;

if (out_xattrs)
{
gs_unref_object GFile *full_path =
_ostree_repo_get_object_path (self, checksum, OSTREE_OBJECT_TYPE_FILE);

if (!gs_file_get_all_xattrs (full_path, &ret_xattrs,
cancellable, error))
if (!gs_fd_get_all_xattrs (fd, &ret_xattrs,
cancellable, error))
goto out;
}
}

if (out_input && g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_REGULAR)
if (out_input)
{
ret_input = g_unix_input_stream_new (fd, TRUE);
fd = -1; /* Transfer ownership */
}
}
else if (g_file_info_get_file_type (ret_file_info) == G_FILE_TYPE_SYMBOLIC_LINK
&& out_xattrs)
{
int fd = -1;
if (!gs_file_openat_noatime (self->objects_dir_fd, loose_path_buf, &fd,
cancellable, error))
if (!gs_dfd_and_name_get_all_xattrs (self->objects_dir_fd, loose_path_buf,
&ret_xattrs,
cancellable, error))
goto out;
ret_input = g_unix_input_stream_new (fd, TRUE);
}

found = TRUE;
Expand Down

0 comments on commit 86764db

Please sign in to comment.