From b7967864aa1da0876e2193b754c16e63918715ce Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Fri, 20 Jan 2017 13:08:15 -0500 Subject: [PATCH 1/2] cli.test: failing test on stdin manifest behavior ought to be, when `-f ` is not provided, then expect the manifest to be provided on stdin. Currently gomtree just fails if there is no `-f` (and it is not `-c`) Signed-off-by: Vincent Batts --- test/cli/0008.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/cli/0008.sh diff --git a/test/cli/0008.sh b/test/cli/0008.sh new file mode 100644 index 0000000..b32d43e --- /dev/null +++ b/test/cli/0008.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +name=$(basename $0) +root="$(dirname $(dirname $(dirname $0)))" +gomtree=$(readlink -f ${root}/gomtree) +t=$(mktemp -d /tmp/go-mtree.XXXXXX) + +echo "[${name}] Running in ${t}" + +pushd ${root} +mkdir -p ${t}/extract +git archive --format=tar HEAD^{tree} . | tar -C ${t}/extract/ -x + +${gomtree} -K sha256digest -c -p ${t}/extract/ > ${t}/${name}.mtree + +## This is a use-case for checking a directory, but by reading the manifest from stdin +## since the `-f` flag is not provided. +cat ${t}/${name}.mtree | ${gomtree} -p ${t}/extract/ + +popd +rm -rf ${t} From 21a2577f0184ab8d6ee153c1f8dae013f36750e5 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Fri, 20 Jan 2017 13:13:59 -0500 Subject: [PATCH 2/2] gomtree: allow manifest to be provided on stdin like `gomtree -c -p /tmp/dir1 -K sha1 | gomtree -p /tmp/dir2` Signed-off-by: Vincent Batts --- cmd/gomtree/main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/gomtree/main.go b/cmd/gomtree/main.go index acca098..2f97690 100644 --- a/cmd/gomtree/main.go +++ b/cmd/gomtree/main.go @@ -257,6 +257,19 @@ func app() error { return nil } + // no spec manifest has been provided yet, so look for it on stdin + if specDh == nil { + // load the hierarchy + specDh, err = mtree.ParseSpec(os.Stdin) + if err != nil { + return err + } + + // We can't check against more fields than in the specKeywords list, so + // currentKeywords can only have a subset of specKeywords. + specKeywords = specDh.UsedKeywords() + } + // This is a validation. if specDh != nil && stateDh != nil { var res []mtree.InodeDelta