lib/repofile: Follow symlinks for g_file_read()

This avoids `ostree cat /path/to/symlink` crashing, a longstanding embarassing
issue.

Closes: #915
Approved by: jlebon
This commit is contained in:
Colin Walters authored and Atomic Bot committed 2017-06-07 20:54:32 +00:00
1 parent 807a804b16
commit d3900f90f4
2 files changed
+38 -2

No files matched your search

+16 -2
View File
@@ -928,9 +928,23 @@ ostree_repo_file_read (GFile *file,
checksum = ostree_repo_file_get_checksum (self);
if (!ostree_repo_load_file (self->repo, checksum, &ret_stream,
NULL, NULL, cancellable, error))
g_autoptr(GFileInfo) finfo = NULL;
if (!ostree_repo_load_file (self->repo, checksum, NULL,
&finfo, NULL, cancellable, error))
return NULL;
if (g_file_info_get_file_type (finfo) == G_FILE_TYPE_REGULAR)
{
if (!ostree_repo_load_file (self->repo, checksum, &ret_stream,
NULL, NULL, cancellable, error))
return NULL;
}
else
{
g_autoptr(GFile) parent = g_file_get_parent (file);
const char *target = g_file_info_get_symlink_target (finfo);
g_autoptr(GFile) dest = g_file_resolve_relative_path (parent, target);
return g_file_read (dest, cancellable, error);
}
return g_steal_pointer (&ret_stream);
}