Skip to content

Commit

Permalink
Merge pull request #4 from deadc0de6/fix-3
Browse files Browse the repository at this point in the history
Fix nested dirs with same names
  • Loading branch information
deadc0de6 authored Jun 3, 2024
2 parents 68352bc + 3d6d002 commit 90d66f0
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

var (
version = "1.0.2"
version = "1.0.3"
myName = "gocatcli"
defCatalog = "gocatcli.catalog"
loadedTree *tree.Tree
Expand Down
3 changes: 2 additions & 1 deletion internal/walker/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func (w *Walker) walk(storageID int, walkPath string, storagePath string, parent
// skipping
return nil
}
if filepath.Base(pathUnderRoot) == filepath.Base(walkPath) {

if pathUnderRoot == walkPath {
//log.Debugf("skipping \"%s\"", pathUnderRoot)
// skipping
return nil
Expand Down
66 changes: 66 additions & 0 deletions tests-ng/test-nested-same-name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2024, deadc0de6
#
# test for nested directories with same names
# for https://github.com/deadc0de6/gocatcli/issues/3
#

## start-test-cookie
set -eu -o errtrace -o pipefail
cur=$(cd "$(dirname "${0}")" && pwd)
bin="${cur}/../bin/gocatcli"
[ ! -e "${bin}" ] && echo "\"${bin}\" not found" && exit 1
# shellcheck disable=SC1091
source "${cur}"/helpers
## end-test-cookie

######################################
## the test

tmpd=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
tmpx=$(mktemp -d --suffix='-dotdrop-tests' || mktemp -d)
clear_on_exit "${tmpd}"
clear_on_exit "${tmpx}"

catalog="${tmpd}/catalog"
out="${tmpd}/output.txt"

# create hierarchy
top="${tmpx}/top"
sup="${top}/artist"
sub="${sup}/artist"
subf="${sub}/sub-file"
supf="${sup}/sup-file"
topf="${top}/top-file"
mkdir -p "${sub}"
echo "sub-file" > "${subf}"
echo "sup-file" > "${supf}"
echo "top-file" > "${topf}"

# index
echo ">>> index dir <<<"
"${bin}" index -a -C --debug -c "${catalog}" --ignore=".git" "${top}" top
[ ! -e "${catalog}" ] && echo "catalog not created" && exit 1

# ls
echo ">>> ls catalog <<<"
"${bin}" -c "${catalog}" ls -a -r | sed -e 's/\x1b\[[0-9;]*m//g' | sed 's/[[:space:]]*$//' > "${out}"

cat > "${tmpx}/expected" << _EOF
storage top
artist
artist
sub-file
sup-file
top-file
_EOF

if hash delta >/dev/null 2>&1; then
delta "${tmpx}/expected" "${out}"
else
diff -w --suppress-common-lines "${tmpx}/expected" "${out}"
fi

echo "test $(basename "${0}") OK!"
exit 0

0 comments on commit 90d66f0

Please sign in to comment.