Skip to content

Commit

Permalink
Merge pull request #198 from vbatts/incorporate_subcommand
Browse files Browse the repository at this point in the history
*: begin incorporating the "validate" subcommand
  • Loading branch information
vbatts authored Oct 24, 2023
2 parents 48e5e86 + e19072a commit c216f6c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,31 @@ To use the command line tool, first [build it](#Building), then the following.
This will also include the sha512 digest of the files.

```shell
gomtree -c -K sha512digest -p . > /tmp/root.mtree
gomtree validate -c -K sha512digest -p . > /tmp/root.mtree
```

With a tar file:

```shell
gomtree -c -K sha512digest -T sometarfile.tar > /tmp/tar.mtree
gomtree validate -c -K sha512digest -T sometarfile.tar > /tmp/tar.mtree
```

### Validate a manifest

```shell
gomtree -p . -f /tmp/root.mtree
gomtree validate -p . -f /tmp/root.mtree
```

With a tar file:

```shell
gomtree -T sometarfile.tar -f /tmp/root.mtree
gomtree validate -T sometarfile.tar -f /tmp/root.mtree
```

### See the supported keywords

```shell
gomtree -list-keywords
gomtree validate -list-keywords
Available keywords:
uname
sha1
Expand Down
1 change: 1 addition & 0 deletions cmd/gomtree/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
func NewValidateCommand() *cli.Command {
return &cli.Command{
Name: "validate",
Usage: "Create and validate a filesystem hierarchy (this is default tool behavior)",
Action: validateAction,
Flags: []cli.Flag{
// Flags common with mtree(8)
Expand Down
44 changes: 44 additions & 0 deletions test/cli/0001a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -e

name=$(basename $0)
root="$(dirname $(dirname $(dirname $0)))"
gomtree=$(go run ${root}/test/realpath/main.go ${root}/gomtree)
t=$(mktemp -d -t go-mtree.XXXXXX)

echo "[${name}] Running in ${t}"
# This test is for basic running check of manifest, and check against tar and file system
#

pushd ${root}

git archive --format=tar -o "${t}/${name}.tar" HEAD^{tree}

prev_umask=$(umask)
umask 0 # this is so the tar command can set the mode's properly
mkdir -p ${t}/extract
tar -C ${t}/extract/ -xf "${t}/${name}.tar"
umask ${prev_umask}

# create manifest from tar
${gomtree} validate -K sha256digest -c -T "${t}/${name}.tar" > "${t}/${name}.mtree"

# check tar-manifest against the tar
${gomtree} validate -f ${t}/${name}.mtree -T "${t}/${name}.tar"

# check tar-manifest against the filesystem
# git archive makes the uid/gid as 0, so don't check them for this test
${gomtree} validate -k size,sha256digest,mode,type -f "${t}/${name}.mtree" -p ${t}/extract/

# create a manifest from filesystem
${gomtree} validate -K sha256digest -c -p "${t}/extract/" > "${t}/${name}.mtree"

# check filesystem-manifest against the filesystem
${gomtree} validate -f "${t}/${name}.mtree" -p "${t}/extract/"

# check filesystem-manifest against the tar
# git archive makes the uid/gid as 0, so don't check them for this test
${gomtree} validate -k size,sha256digest,mode,type -f "${t}/${name}.mtree" -T "${t}/${name}.tar"

popd
rm -rf ${t}

0 comments on commit c216f6c

Please sign in to comment.