Skip to content

Commit c216f6c

Browse files
authored
Merge pull request #198 from vbatts/incorporate_subcommand
*: begin incorporating the "validate" subcommand
2 parents 48e5e86 + e19072a commit c216f6c

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,31 +104,31 @@ To use the command line tool, first [build it](#Building), then the following.
104104
This will also include the sha512 digest of the files.
105105

106106
```shell
107-
gomtree -c -K sha512digest -p . > /tmp/root.mtree
107+
gomtree validate -c -K sha512digest -p . > /tmp/root.mtree
108108
```
109109

110110
With a tar file:
111111

112112
```shell
113-
gomtree -c -K sha512digest -T sometarfile.tar > /tmp/tar.mtree
113+
gomtree validate -c -K sha512digest -T sometarfile.tar > /tmp/tar.mtree
114114
```
115115

116116
### Validate a manifest
117117

118118
```shell
119-
gomtree -p . -f /tmp/root.mtree
119+
gomtree validate -p . -f /tmp/root.mtree
120120
```
121121

122122
With a tar file:
123123

124124
```shell
125-
gomtree -T sometarfile.tar -f /tmp/root.mtree
125+
gomtree validate -T sometarfile.tar -f /tmp/root.mtree
126126
```
127127

128128
### See the supported keywords
129129

130130
```shell
131-
gomtree -list-keywords
131+
gomtree validate -list-keywords
132132
Available keywords:
133133
uname
134134
sha1

cmd/gomtree/cmd/validate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
func NewValidateCommand() *cli.Command {
1616
return &cli.Command{
1717
Name: "validate",
18+
Usage: "Create and validate a filesystem hierarchy (this is default tool behavior)",
1819
Action: validateAction,
1920
Flags: []cli.Flag{
2021
// Flags common with mtree(8)

test/cli/0001a.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -e
3+
4+
name=$(basename $0)
5+
root="$(dirname $(dirname $(dirname $0)))"
6+
gomtree=$(go run ${root}/test/realpath/main.go ${root}/gomtree)
7+
t=$(mktemp -d -t go-mtree.XXXXXX)
8+
9+
echo "[${name}] Running in ${t}"
10+
# This test is for basic running check of manifest, and check against tar and file system
11+
#
12+
13+
pushd ${root}
14+
15+
git archive --format=tar -o "${t}/${name}.tar" HEAD^{tree}
16+
17+
prev_umask=$(umask)
18+
umask 0 # this is so the tar command can set the mode's properly
19+
mkdir -p ${t}/extract
20+
tar -C ${t}/extract/ -xf "${t}/${name}.tar"
21+
umask ${prev_umask}
22+
23+
# create manifest from tar
24+
${gomtree} validate -K sha256digest -c -T "${t}/${name}.tar" > "${t}/${name}.mtree"
25+
26+
# check tar-manifest against the tar
27+
${gomtree} validate -f ${t}/${name}.mtree -T "${t}/${name}.tar"
28+
29+
# check tar-manifest against the filesystem
30+
# git archive makes the uid/gid as 0, so don't check them for this test
31+
${gomtree} validate -k size,sha256digest,mode,type -f "${t}/${name}.mtree" -p ${t}/extract/
32+
33+
# create a manifest from filesystem
34+
${gomtree} validate -K sha256digest -c -p "${t}/extract/" > "${t}/${name}.mtree"
35+
36+
# check filesystem-manifest against the filesystem
37+
${gomtree} validate -f "${t}/${name}.mtree" -p "${t}/extract/"
38+
39+
# check filesystem-manifest against the tar
40+
# git archive makes the uid/gid as 0, so don't check them for this test
41+
${gomtree} validate -k size,sha256digest,mode,type -f "${t}/${name}.mtree" -T "${t}/${name}.tar"
42+
43+
popd
44+
rm -rf ${t}

0 commit comments

Comments
 (0)