Add nvm_tree_contains_path function
parent
200a9aa97e
commit
1c50c5c7aa
13
nvm.sh
13
nvm.sh
|
@ -53,6 +53,19 @@ if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then
|
||||||
export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist"
|
export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
nvm_tree_contains_path() {
|
||||||
|
local tree
|
||||||
|
tree="$1"
|
||||||
|
local path
|
||||||
|
path="$2"
|
||||||
|
local pathdir
|
||||||
|
pathdir=$(dirname "$path")
|
||||||
|
while [ "$pathdir" != "" ] && [ "$pathdir" != "." ] && [ "$pathdir" != "/" ] && [ "$pathdir" != "$tree" ]; do
|
||||||
|
pathdir=$(dirname "$pathdir")
|
||||||
|
done
|
||||||
|
[ "$pathdir" = "$tree" ]
|
||||||
|
}
|
||||||
|
|
||||||
# Traverse up in directory tree to find containing folder
|
# Traverse up in directory tree to find containing folder
|
||||||
nvm_find_up() {
|
nvm_find_up() {
|
||||||
local path
|
local path
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
cleanup () {
|
||||||
|
rm tmp/node
|
||||||
|
rmdir tmp
|
||||||
|
rm tmp2/node
|
||||||
|
rmdir tmp2
|
||||||
|
}
|
||||||
|
die () { echo $@ ; cleanup; exit 1; }
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
|
||||||
|
mkdir -p tmp
|
||||||
|
touch -p tmp/node
|
||||||
|
mkdir -p tmp2
|
||||||
|
touch -p tmp2/node
|
||||||
|
|
||||||
|
nvm_tree_contains_path tmp tmp/node || die '"tmp" should contain "tmp/node"'
|
||||||
|
|
||||||
|
nvm_tree_contains_path tmp tmp2/node && die '"tmp" should not contain "tmp2/node"'
|
||||||
|
|
||||||
|
nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"'
|
||||||
|
|
||||||
|
nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"'
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
Loading…
Reference in New Issue