[ostree] ls: Add mode to print filenames as binary
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] ls: Add mode to print filenames as binary
- Date: Sun, 8 Apr 2012 21:27:34 +0000 (UTC)
commit 92ab820c0bf002f4ac2b2b5b3e32068830627fbe
Author: Colin Walters <walters verbum org>
Date: Fri Apr 6 15:10:20 2012 -0400
ls: Add mode to print filenames as binary
This is useful to extract the file listing to another program.
src/ostree/ot-builtin-ls.c | 32 ++++++++++++++++++++++++++++++--
1 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/src/ostree/ot-builtin-ls.c b/src/ostree/ot-builtin-ls.c
index 30480b0..5dd29e8 100644
--- a/src/ostree/ot-builtin-ls.c
+++ b/src/ostree/ot-builtin-ls.c
@@ -31,16 +31,19 @@
static gboolean recursive;
static gboolean checksum;
static gboolean xattrs;
+static gboolean opt_nul_filenames_only;
static GOptionEntry options[] = {
{ "recursive", 'R', 0, G_OPTION_ARG_NONE, &recursive, "Print directories recursively", NULL },
{ "checksum", 'C', 0, G_OPTION_ARG_NONE, &checksum, "Print checksum", NULL },
{ "xattrs", 'X', 0, G_OPTION_ARG_NONE, &xattrs, "Print extended attributes", NULL },
+ { "nul-filenames-only", 0, 0, G_OPTION_ARG_NONE, &opt_nul_filenames_only, "Print only filenames, NUL separated", NULL },
+ { NULL }
};
static void
-print_one_file (GFile *f,
- GFileInfo *file_info)
+print_one_file_text (GFile *f,
+ GFileInfo *file_info)
{
GString *buf = NULL;
char type_c;
@@ -118,6 +121,31 @@ print_one_file (GFile *f,
g_string_free (buf, TRUE);
}
+static void
+print_one_file_binary (GFile *f,
+ GFileInfo *file_info)
+{
+ const char *path;
+
+ if (!ostree_repo_file_ensure_resolved ((OstreeRepoFile*)f, NULL))
+ g_assert_not_reached ();
+
+ path = ot_gfile_get_path_cached (f);
+
+ fwrite (path, 1, strlen (path), stdout);
+ fwrite ("\0", 1, 1, stdout);
+}
+
+static void
+print_one_file (GFile *f,
+ GFileInfo *file_info)
+{
+ if (opt_nul_filenames_only)
+ print_one_file_binary (f, file_info);
+ else
+ print_one_file_text (f, file_info);
+}
+
static gboolean
print_directory_recurse (GFile *f,
GError **error)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]