Created
November 21, 2019 20:37
-
-
Save wgwoods/72947ad94b697ea11d02d40730554946 to your computer and use it in GitHub Desktop.
A little demonstration of how symlinked directories can cause surprising behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Make a little tmpdir (and delete it when we're done) | |
tmpdir=$(mktemp -d) && [ -d $tmpdir ] && trap "rm -rf $tmpdir" EXIT | |
tree1=$tmpdir/tree1 | |
tree2=$tmpdir/tree2 | |
# Make an example tree | |
mkdir -p $tree1/etc/pki/rpm-gpg | |
mkdir -p $tree1/etc/pki/ca-trust | |
echo "TREE1" > $tree1/etc/tree-id | |
# Make another, but symlink one of the dirs | |
mkdir -p $tree2/etc/pki/rpm-gpg | |
ln -rs $tree1/etc/pki/ca-trust $tree2/etc/pki/ca-trust | |
echo "TREE2" > $tree2/etc/tree-id | |
# OK, show what we've got set up. | |
cd $tmpdir | |
set -x | |
find * -ls | |
cat tree1/etc/tree-id # "TREE1" | |
cat tree2/etc/tree-id # "TREE2" | |
# You might think these would all be the same file, but.. nope! | |
cd tree2/etc; cat tree-id # "TREE2" | |
cd pki; cat ../tree-id # "TREE2" | |
cd ca-trust; cat ../../tree-id # "TREE1" (!) | |
{ set +x; } 2>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment