Merge pull request #110 from cyphar/xattr-encode-spaces
keywords: encode xattr.* keywords with Vis
This commit is contained in:
commit
2b97fe83d3
4 changed files with 55 additions and 13 deletions
|
@ -269,14 +269,20 @@ func app() error {
|
|||
if isTarSpec(specDh) || *flTar != "" {
|
||||
res = filterMissingKeywords(res)
|
||||
}
|
||||
//if len(res) > 0 {
|
||||
//return fmt.Errorf("unexpected missing keywords: %d", len(res))
|
||||
//}
|
||||
|
||||
out := formatFunc(res)
|
||||
if _, err := os.Stdout.Write([]byte(out)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: This should be a flag. Allowing files to be added and
|
||||
// removed and still returning "it's all good" is simply
|
||||
// unsafe IMO.
|
||||
for _, diff := range res {
|
||||
if diff.Type() == mtree.Modified {
|
||||
return fmt.Errorf("mainfest validation failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("neither validating or creating a manifest. Please provide additional arguments")
|
||||
|
@ -289,13 +295,7 @@ var formats = map[string]func([]mtree.InodeDelta) string{
|
|||
"bsd": func(d []mtree.InodeDelta) string {
|
||||
var buffer bytes.Buffer
|
||||
for _, delta := range d {
|
||||
if delta.Type() == mtree.Modified {
|
||||
fmt.Fprintln(&buffer, delta)
|
||||
} else if delta.Type() == mtree.Missing {
|
||||
fmt.Fprintln(&buffer, delta)
|
||||
} else if delta.Type() == mtree.Extra {
|
||||
fmt.Fprintln(&buffer, delta)
|
||||
}
|
||||
}
|
||||
return buffer.String()
|
||||
},
|
||||
|
|
|
@ -62,7 +62,11 @@ var (
|
|||
}
|
||||
klist := []KeyVal{}
|
||||
for k, v := range hdr.Xattrs {
|
||||
klist = append(klist, KeyVal(fmt.Sprintf("xattr.%s=%s", k, base64.StdEncoding.EncodeToString([]byte(v)))))
|
||||
encKey, err := Vis(k, DefaultVisFlags)
|
||||
if err != nil {
|
||||
return emptyKV, err
|
||||
}
|
||||
klist = append(klist, KeyVal(fmt.Sprintf("xattr.%s=%s", encKey, base64.StdEncoding.EncodeToString([]byte(v)))))
|
||||
}
|
||||
return KeyVal(strings.Join(KeyValToString(klist), " ")), nil
|
||||
}
|
||||
|
@ -80,7 +84,11 @@ var (
|
|||
if err != nil {
|
||||
return emptyKV, err
|
||||
}
|
||||
klist[i] = KeyVal(fmt.Sprintf("xattr.%s=%s", xlist[i], base64.StdEncoding.EncodeToString(data)))
|
||||
encKey, err := Vis(xlist[i], DefaultVisFlags)
|
||||
if err != nil {
|
||||
return emptyKV, err
|
||||
}
|
||||
klist[i] = KeyVal(fmt.Sprintf("xattr.%s=%s", encKey, base64.StdEncoding.EncodeToString(data)))
|
||||
}
|
||||
return KeyVal(strings.Join(KeyValToString(klist), " ")), nil
|
||||
}
|
||||
|
|
|
@ -17,10 +17,11 @@ func main() {
|
|||
cmd.Stdout = os.Stdout
|
||||
if err := cmd.Run(); err != nil {
|
||||
failed++
|
||||
fmt.Fprintf(os.Stderr, "FAILED: %s\n", arg)
|
||||
}
|
||||
}
|
||||
if failed > 0 {
|
||||
fmt.Printf("%d FAILED tests\n", failed)
|
||||
fmt.Fprintf(os.Stderr, "%d FAILED tests\n", failed)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
33
test/cli/0003.sh
Normal file
33
test/cli/0003.sh
Normal file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
name=$(basename $0)
|
||||
root="$(dirname $(dirname $(dirname $0)))"
|
||||
gomtree=$(readlink -f ${root}/gomtree)
|
||||
t=$(mktemp -d /tmp/go-mtree.XXXXXX)
|
||||
|
||||
setfattr -n user.has_xattrs -v "" "${t}" || exit 0
|
||||
|
||||
echo "[${name}] Running in ${t}"
|
||||
|
||||
mkdir "${t}/dir"
|
||||
touch "${t}/dir/file"
|
||||
|
||||
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
|
||||
|
||||
setfattr -x user.mtree.testing "${t}/dir/file"
|
||||
! $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
|
||||
|
||||
setfattr -n user.mtree.testing -v "apples and=bananas" "${t}/dir/file"
|
||||
setfattr -x user.mtree.another "${t}/dir/file"
|
||||
$gomtree -p ${t}/dir -f ${t}/${name}.mtree
|
||||
|
||||
rm -fr ${t}
|
Loading…
Reference in a new issue