mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-19 22:50:35 +03:00
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:
parent
807a804b16
commit
d3900f90f4
@ -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);
|
||||
}
|
||||
|
@ -338,8 +338,30 @@ $OSTREE prune
|
||||
echo "ok prune didn't fail"
|
||||
|
||||
cd ${test_tmpdir}
|
||||
# Verify we can't cat dirs
|
||||
for path in / /baz; do
|
||||
if $OSTREE cat test2 $path 2>err.txt; then
|
||||
assert_not_reached "cat directory"
|
||||
fi
|
||||
assert_file_has_content err.txt "open directory"
|
||||
done
|
||||
rm checkout-test2 -rf
|
||||
$OSTREE cat test2 /yet/another/tree/green > greenfile-contents
|
||||
assert_file_has_content greenfile-contents "leaf"
|
||||
$OSTREE checkout test2 checkout-test2
|
||||
ls -alR checkout-test2
|
||||
ln -sr checkout-test2/{four,four-link}
|
||||
ln -sr checkout-test2/{baz/cow,cow-link}
|
||||
ln -sr checkout-test2/{cow-link,cow-link-link}
|
||||
$OSTREE commit -b test2-withlink --tree=dir=checkout-test2
|
||||
if $OSTREE cat test2-withlink /four-link 2>err.txt; then
|
||||
assert_not_reached "cat directory"
|
||||
fi
|
||||
assert_file_has_content err.txt "open directory"
|
||||
for path in /cow-link /cow-link-link; do
|
||||
$OSTREE cat test2-withlink $path >contents.txt
|
||||
assert_file_has_content contents.txt moo
|
||||
done
|
||||
echo "ok cat-file"
|
||||
|
||||
cd ${test_tmpdir}
|
||||
|
Loading…
x
Reference in New Issue
Block a user