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
This commit is contained in:
Tristan Van Berkom 2019-05-21 22:26:55 +09:00 committed by Atomic Bot
parent da4d0245af
commit bebd8d6980
1 changed files with 23 additions and 6 deletions

View File

@ -635,13 +635,24 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
else if (strcmp (tree_type, "tar") == 0) else if (strcmp (tree_type, "tar") == 0)
{ {
if (!opt_tar_pathname_filter) if (!opt_tar_pathname_filter)
{
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); object_to_commit = g_file_new_for_path (tree);
if (!ostree_repo_write_archive_to_mtree (repo, object_to_commit, mtree, modifier, if (!ostree_repo_write_archive_to_mtree (repo, object_to_commit, mtree, modifier,
opt_tar_autocreate_parents, opt_tar_autocreate_parents,
cancellable, error)) cancellable, error))
goto out; goto out;
} }
}
else else
{ {
#ifdef HAVE_LIBARCHIVE #ifdef HAVE_LIBARCHIVE
@ -666,7 +677,13 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
goto out; goto out;
} }
opts.translate_pathname_user_data = &tpdata; 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) if (!archive)
goto out; goto out;
if (!ostree_repo_import_archive_to_mtree (repo, &opts, archive, mtree, if (!ostree_repo_import_archive_to_mtree (repo, &opts, archive, mtree,