1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-12-18 03:56:30 +00:00

Merge pull request #182 from vbatts/not_a_directory

walk: directory is expected to be walked. A file is not.
This commit is contained in:
Vincent Batts 2022-04-23 13:42:46 -04:00 committed by GitHub
commit 79927ba184
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

22
test/cli/0011.sh Normal file
View file

@ -0,0 +1,22 @@
#!/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 /tmp/go-mtree.XXXXXX)
echo "[${name}] Running in ${t}"
## testing comparing two files
pushd ${root}
mkdir -p ${t}/
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
popd
rm -rf ${t}

View file

@ -33,6 +33,11 @@ func Walk(root string, excludes []ExcludeFunc, keywords []Keyword, fsEval FsEval
if fsEval == nil {
fsEval = DefaultFsEval{}
}
if info, err := os.Stat(root); err == nil {
if !info.IsDir() {
return nil, fmt.Errorf("%s: Not a directory", filepath.Base(root))
}
}
creator := dhCreator{DH: &DirectoryHierarchy{}, fs: fsEval}
// insert signature and metadata comments first (user, machine, tree, date)
for _, e := range signatureEntries(root) {