1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-09-13 22:03:19 +00:00

Merge pull request #207 from cyphar/error-exit-code

gomtree: return exit status != 0 on error
This commit is contained in:
Vincent Batts 2025-09-08 10:40:09 -04:00 committed by GitHub
commit b454bc0bdd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 14 additions and 18 deletions

View file

@ -1,7 +1,6 @@
package main
import (
"fmt"
"os"
"strings"
@ -51,23 +50,20 @@ to support xattrs and interacting with tar archives.`
app.OnUsageError = func(ctx *cli.Context, err error, isSubcommand bool) error {
if ctx.Command.Name == "gomtree" && strings.Contains(err.Error(), "flag provided but not defined") {
runValidate = true
return nil
}
return err
}
if err := app.Run(os.Args); err != nil {
fmt.Println(err.Error())
}
// So we run the command again with the validate command as the default.
if runValidate {
err := app.Run(os.Args)
// If it failed, run the command again with the validate command as the
// default if it failed.
if err != nil && runValidate {
app.OnUsageError = nil
args := []string{os.Args[0], "validate"}
args = append(args, os.Args[1:]...)
if err := app.Run(args); err != nil {
fmt.Println(err.Error())
err = app.Run(args)
}
if err != nil {
logrus.Fatal(err)
}
}

View file

@ -17,14 +17,14 @@ setfattr -n user.mtree.testing -v "apples and=bananas" "${t}/dir/file"
$gomtree -c -k "sha256digest,xattrs" -p ${t}/dir > ${t}/${name}.mtree
setfattr -n user.mtree.testing -v "bananas and lemons" "${t}/dir/file"
! $gomtree -p ${t}/dir -f ${t}/${name}.mtree
(! $gomtree -p ${t}/dir -f ${t}/${name}.mtree)
setfattr -x user.mtree.testing "${t}/dir/file"
! $gomtree -p ${t}/dir -f ${t}/${name}.mtree
(! $gomtree -p ${t}/dir -f ${t}/${name}.mtree)
setfattr -n user.mtree.testing -v "apples and=bananas" "${t}/dir/file"
setfattr -n user.mtree.another -v "another a=b" "${t}/dir/file"
! $gomtree -p ${t}/dir -f ${t}/${name}.mtree
(! $gomtree -p ${t}/dir -f ${t}/${name}.mtree)
setfattr -n user.mtree.testing -v "apples and=bananas" "${t}/dir/file"
setfattr -x user.mtree.another "${t}/dir/file"

View file

@ -24,7 +24,7 @@ ${gomtree} -k uid,gid,size,type,link,nlink,sha256digest -f ${t}/root.mtree -p ${
# Modify it and make sure that it successfully figures out what changed.
echo "othe data" > "${t}/root/$(printf 'this file has \u042a some unicode !!')"
! ${gomtree} -k uid,gid,size,type,link,nlink,sha256digest -f ${t}/root.mtree -p ${t}/root
(! ${gomtree} -k uid,gid,size,type,link,nlink,sha256digest -f ${t}/root.mtree -p ${t}/root)
echo "some data" > "${t}/root/$(printf 'this file has \u042a some unicode !!')"
${gomtree} -k uid,gid,size,type,link,nlink,sha256digest -f ${t}/root.mtree -p ${t}/root

View file

@ -19,7 +19,7 @@ rm -rf ${t}/extract/*.go
${gomtree} -K sha256digest -c -p ${t}/extract/ > ${t}/${name}-2.mtree
# this _ought_ to fail because the files are missing now
! ${gomtree} -f ${t}/${name}-1.mtree -f ${t}/${name}-2.mtree
(! ${gomtree} -f ${t}/${name}-1.mtree -f ${t}/${name}-2.mtree)
popd
rm -rf ${t}

View file

@ -16,7 +16,7 @@ touch ${t}/foo
## can not walk a file. We're expecting a directory.
## https://github.com/vbatts/go-mtree/issues/166
! ${gomtree} -c -K uname,uid,gname,gid,type,nlink,link,mode,flags,xattr,xattrs,size,time,sha256 -p ${t}/foo
(! ${gomtree} -c -K uname,uid,gname,gid,type,nlink,link,mode,flags,xattr,xattrs,size,time,sha256 -p ${t}/foo)
popd
rm -rf ${t}