From bebd8d6980f8ec0a182d2b69073b55085580a29c Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Tue, 21 May 2019 22:26:55 +0900 Subject: [PATCH] bin/commit: Support committing archives from stdin This commit interprets archive filenames specified as '-' to indicate that the input should be read from stdin. Closes: #1862 Approved by: jlebon --- src/ostree/ot-builtin-commit.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index b7c61a9e..56f59681 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -636,11 +636,22 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio { if (!opt_tar_pathname_filter) { - object_to_commit = g_file_new_for_path (tree); - if (!ostree_repo_write_archive_to_mtree (repo, object_to_commit, mtree, modifier, - opt_tar_autocreate_parents, - cancellable, error)) - goto out; + if (strcmp (tree, "-") == 0) + { + if (!ostree_repo_write_archive_to_mtree_from_fd (repo, STDIN_FILENO, mtree, modifier, + opt_tar_autocreate_parents, + cancellable, error)) + goto out; + } + else + { + object_to_commit = g_file_new_for_path (tree); + + if (!ostree_repo_write_archive_to_mtree (repo, object_to_commit, mtree, modifier, + opt_tar_autocreate_parents, + cancellable, error)) + goto out; + } } else { @@ -666,7 +677,13 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio goto out; } opts.translate_pathname_user_data = &tpdata; - g_autoptr(OtAutoArchiveRead) archive = ot_open_archive_read (tree, error); + + g_autoptr(OtAutoArchiveRead) archive; + if (strcmp (tree, "-") == 0) + archive = ot_open_archive_read_fd (STDIN_FILENO, error); + else + archive = ot_open_archive_read (tree, error); + if (!archive) goto out; if (!ostree_repo_import_archive_to_mtree (repo, &opts, archive, mtree,