main: ls: Behave like standard Unix "ls" with directories
Default to listing directory contents, add -d/--dironly to suppress this.
This commit is contained in:
parent
4de1d51266
commit
3ea62abe75
|
|
@ -26,12 +26,14 @@
|
||||||
#include "ostree.h"
|
#include "ostree.h"
|
||||||
#include "ostree-repo-file.h"
|
#include "ostree-repo-file.h"
|
||||||
|
|
||||||
|
static gboolean opt_dironly;
|
||||||
static gboolean opt_recursive;
|
static gboolean opt_recursive;
|
||||||
static gboolean opt_checksum;
|
static gboolean opt_checksum;
|
||||||
static gboolean opt_xattrs;
|
static gboolean opt_xattrs;
|
||||||
static gboolean opt_nul_filenames_only;
|
static gboolean opt_nul_filenames_only;
|
||||||
|
|
||||||
static GOptionEntry options[] = {
|
static GOptionEntry options[] = {
|
||||||
|
{ "dironly", 'd', 0, G_OPTION_ARG_NONE, &opt_dironly, "Do not recurse into directory arguments", NULL },
|
||||||
{ "recursive", 'R', 0, G_OPTION_ARG_NONE, &opt_recursive, "Print directories recursively", NULL },
|
{ "recursive", 'R', 0, G_OPTION_ARG_NONE, &opt_recursive, "Print directories recursively", NULL },
|
||||||
{ "checksum", 'C', 0, G_OPTION_ARG_NONE, &opt_checksum, "Print checksum", NULL },
|
{ "checksum", 'C', 0, G_OPTION_ARG_NONE, &opt_checksum, "Print checksum", NULL },
|
||||||
{ "xattrs", 'X', 0, G_OPTION_ARG_NONE, &opt_xattrs, "Print extended attributes", NULL },
|
{ "xattrs", 'X', 0, G_OPTION_ARG_NONE, &opt_xattrs, "Print extended attributes", NULL },
|
||||||
|
|
@ -146,6 +148,7 @@ print_one_file (GFile *f,
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
print_directory_recurse (GFile *f,
|
print_directory_recurse (GFile *f,
|
||||||
|
int depth,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
@ -154,6 +157,13 @@ print_directory_recurse (GFile *f,
|
||||||
gs_unref_object GFileInfo *child_info = NULL;
|
gs_unref_object GFileInfo *child_info = NULL;
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
|
|
||||||
|
if (depth > 0)
|
||||||
|
depth--;
|
||||||
|
else if (depth == 0)
|
||||||
|
return TRUE;
|
||||||
|
else
|
||||||
|
g_assert (depth == -1);
|
||||||
|
|
||||||
dir_enum = g_file_enumerate_children (f, OSTREE_GIO_FAST_QUERYINFO,
|
dir_enum = g_file_enumerate_children (f, OSTREE_GIO_FAST_QUERYINFO,
|
||||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
@ -170,7 +180,7 @@ print_directory_recurse (GFile *f,
|
||||||
|
|
||||||
if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY)
|
if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY)
|
||||||
{
|
{
|
||||||
if (!print_directory_recurse (child, error))
|
if (!print_directory_recurse (child, depth, error))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,11 +243,19 @@ ostree_builtin_ls (int argc, char **argv, GFile *repo_path, GCancellable *cancel
|
||||||
|
|
||||||
print_one_file (f, file_info);
|
print_one_file (f, file_info);
|
||||||
|
|
||||||
if (opt_recursive && g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
|
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
|
||||||
{
|
{
|
||||||
if (!print_directory_recurse (f, error))
|
if (opt_recursive)
|
||||||
|
{
|
||||||
|
if (!print_directory_recurse (f, -1, error))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
else if (!opt_dironly)
|
||||||
|
{
|
||||||
|
if (!print_directory_recurse (f, 1, error))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue