Skip to content

Commit 5d7f6c3

Browse files
committed
walk: directory is expected to be walked. A file is not.
Fixes: #166 Signed-off-by: Vincent Batts <[email protected]>
1 parent b9356e6 commit 5d7f6c3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

test/cli/0011.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 /tmp/go-mtree.XXXXXX)
8+
9+
echo "[${name}] Running in ${t}"
10+
11+
## testing comparing two files
12+
13+
pushd ${root}
14+
mkdir -p ${t}/
15+
touch ${t}/foo
16+
17+
## can not walk a file. We're expecting a directory.
18+
## https://github.com/vbatts/go-mtree/issues/166
19+
! ${gomtree} -c -K uname,uid,gname,gid,type,nlink,link,mode,flags,xattr,xattrs,size,time,sha256 -p ${t}/foo
20+
21+
popd
22+
rm -rf ${t}

walk.go

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

0 commit comments

Comments
 (0)