1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-14 12:48:44 +00:00

Merge pull request #198 from vbatts/incorporate_subcommand

*: begin incorporating the "validate" subcommand
This commit is contained in:
Vincent Batts 2023-10-24 16:05:24 -04:00 committed by GitHub
commit c216f6c013
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 5 deletions

View file

@ -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

View file

@ -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)

44
test/cli/0001a.sh Normal file
View file

@ -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}