Skip to content

Commit 90d66f0

Browse files
authored
Merge pull request #4 from deadc0de6/fix-3
Fix nested dirs with same names
2 parents 68352bc + 3d6d002 commit 90d66f0

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

internal/commands/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
)
2121

2222
var (
23-
version = "1.0.2"
23+
version = "1.0.3"
2424
myName = "gocatcli"
2525
defCatalog = "gocatcli.catalog"
2626
loadedTree *tree.Tree

internal/walker/walker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func (w *Walker) walk(storageID int, walkPath string, storagePath string, parent
3636
// skipping
3737
return nil
3838
}
39-
if filepath.Base(pathUnderRoot) == filepath.Base(walkPath) {
39+
40+
if pathUnderRoot == walkPath {
4041
//log.Debugf("skipping \"%s\"", pathUnderRoot)
4142
// skipping
4243
return nil

tests-ng/test-nested-same-name.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
# author: deadc0de6 (https://github.com/deadc0de6)
3+
# Copyright (c) 2024, deadc0de6
4+
#
5+
# test for nested directories with same names
6+
# for https://github.com/deadc0de6/gocatcli/issues/3
7+
#
8+
9+
## start-test-cookie
10+
set -eu -o errtrace -o pipefail
11+
cur=$(cd "$(dirname "${0}")" && pwd)
12+
bin="${cur}/../bin/gocatcli"
13+
[ ! -e "${bin}" ] && echo "\"${bin}\" not found" && exit 1
14+
# shellcheck disable=SC1091
15+
source "${cur}"/helpers
16+
## end-test-cookie
17+
18+
######################################
19+
## the test
20+
21+
tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
22+
tmpx=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
23+
clear_on_exit "${tmpd}"
24+
clear_on_exit "${tmpx}"
25+
26+
catalog="${tmpd}/catalog"
27+
out="${tmpd}/output.txt"
28+
29+
# create hierarchy
30+
top="${tmpx}/top"
31+
sup="${top}/artist"
32+
sub="${sup}/artist"
33+
subf="${sub}/sub-file"
34+
supf="${sup}/sup-file"
35+
topf="${top}/top-file"
36+
mkdir -p "${sub}"
37+
echo "sub-file" > "${subf}"
38+
echo "sup-file" > "${supf}"
39+
echo "top-file" > "${topf}"
40+
41+
# index
42+
echo ">>> index dir <<<"
43+
"${bin}" index -a -C --debug -c "${catalog}" --ignore=".git" "${top}" top
44+
[ ! -e "${catalog}" ] && echo "catalog not created" && exit 1
45+
46+
# ls
47+
echo ">>> ls catalog <<<"
48+
"${bin}" -c "${catalog}" ls -a -r | sed -e 's/\x1b\[[0-9;]*m//g' | sed 's/[[:space:]]*$//' > "${out}"
49+
50+
cat > "${tmpx}/expected" << _EOF
51+
storage top
52+
artist
53+
artist
54+
sub-file
55+
sup-file
56+
top-file
57+
_EOF
58+
59+
if hash delta >/dev/null 2>&1; then
60+
delta "${tmpx}/expected" "${out}"
61+
else
62+
diff -w --suppress-common-lines "${tmpx}/expected" "${out}"
63+
fi
64+
65+
echo "test $(basename "${0}") OK!"
66+
exit 0

0 commit comments

Comments
 (0)