Skip to content

Commit

Permalink
ostree ls: Accept any treeish in place of COMMIT
Browse files Browse the repository at this point in the history
This is a generalisation of ostree ls to be consistent with other  places
we accept a treeish.  It doesn't behave quite as you might expect: the
printed paths are always relative to the commit root rather than to the
treeish passed in.  So:

    ostree ls :rootfs:usr/bin systemd

Prints:

    -00755 0 0  12345 /usr/bin/systemd

rather than

    -00755 0 0  12345 systemd

as you might expect.  I think it would be nice to change this behaviour,
but it would be backwards-incompatible so it can't happen.
  • Loading branch information
wmanley committed Jul 9, 2018
1 parent 9c7b19c commit 66c762c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
20 changes: 12 additions & 8 deletions src/ostree/ot-builtin-ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "ostree.h"
#include "ostree-repo-file.h"
#include "otutil.h"
#include "ostree-cmdprivate.h"

static gboolean opt_dironly;
static gboolean opt_recursive;
Expand Down Expand Up @@ -212,8 +213,11 @@ print_one_argument (OstreeRepo *repo,
g_autoptr(GFile) f = NULL;
g_autoptr(GFileInfo) file_info = NULL;

f = g_file_resolve_relative_path (root, arg);

if (arg)
f = g_file_resolve_relative_path (root, arg);
else
f = g_object_ref (root);

file_info = g_file_query_info (f, OSTREE_GIO_FAST_QUERYINFO,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
cancellable, error);
Expand Down Expand Up @@ -247,9 +251,8 @@ ostree_builtin_ls (int argc, char **argv, OstreeCommandInvocation *invocation, G
g_autoptr(GOptionContext) context = NULL;
g_autoptr(OstreeRepo) repo = NULL;
gboolean ret = FALSE;
const char *rev;
int i;
g_autoptr(GFile) root = NULL;
g_autoptr(OstreeRepoFile) root = NULL;

context = g_option_context_new ("COMMIT [PATH...]");

Expand All @@ -261,22 +264,23 @@ ostree_builtin_ls (int argc, char **argv, OstreeCommandInvocation *invocation, G
ot_util_usage_error (context, "An COMMIT argument is required", error);
goto out;
}
rev = argv[1];

if (!ostree_repo_read_commit (repo, rev, &root, NULL, cancellable, error))
if (!ostree_cmd__private__ ()->ostree_repo_open_file (
repo, argv[1], NULL, OSTREE_REPO_OPEN_FILE_EXPECT_TREE |
OSTREE_REPO_OPEN_FILE_EXPECT_FILE, &root, NULL, cancellable, error))
goto out;

if (argc > 2)
{
for (i = 2; i < argc; i++)
{
if (!print_one_argument (repo, root, argv[i], cancellable, error))
if (!print_one_argument (repo, (GFile*) root, argv[i], cancellable, error))
goto out;
}
}
else
{
if (!print_one_argument (repo, root, "/", cancellable, error))
if (!print_one_argument (repo, (GFile*) root, NULL, cancellable, error))
goto out;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/basic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ $OSTREE prune --refs-only
if $OSTREE ls ${orphaned_rev} 2>err.txt; then
assert_not_reached "Found orphaned commit"
fi
assert_file_has_content err.txt "No such metadata object"
assert_file_has_content err.txt "error: No DIR_TREE or COMMIT found for sha "
echo "ok commit orphaned"

cd ${test_tmpdir}
Expand Down
6 changes: 4 additions & 2 deletions tests/test-basic-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ done
echo 'some rootfs data' > rootfs/usr/lib/cache.txt
$OSTREE commit -b rootfs --link-checkout-speedup --tree=dir=rootfs
$OSTREE ls rootfs /usr/bin/systemd >ls.txt
assert_file_has_content ls.txt '^-007.. 0 0 .*/usr/bin/systemd'
assert_file_has_content ls.txt '^-007.. 0 0 .* /usr/bin/systemd'
$OSTREE ls :rootfs:usr/bin systemd >ls.txt
assert_file_has_content ls.txt '^-007.. 0 0 .* /usr/bin/systemd'
$OSTREE ls rootfs /usr/lib/dbus-daemon-helper >ls.txt
assert_file_has_content ls.txt '^-007.. 0 81 .*/usr/lib/dbus-daemon-helper'
assert_file_has_content ls.txt '^-007.. 0 81 .* /usr/lib/dbus-daemon-helper'
echo "ok bare-user link-checkout-speedup maintains uids"

cd ${test_tmpdir}
Expand Down

0 comments on commit 66c762c

Please sign in to comment.