| 1 |
#!/bin/sh -vx |
| 2 |
# $Id: cnfnlink.test 76831 2025-11-11 23:41:11Z karl $ |
| 3 |
# Copyright 2025 Karl Berry <[email protected]> |
| 4 |
# You may freely use, modify and/or distribute this file. |
| 5 |
# |
| 6 |
# Test configuration value for enabling/disabling the check for |
| 7 |
# st_nlink=2 to determine leaf directories. For the problem reports that |
| 8 |
# motivated this, see the "Subdirectory expansion" node in the Kpathsea manual. |
| 9 |
|
| 10 |
BinDir=${BinDir:-.} |
| 11 |
ExeExt=${ExeExt:-} |
| 12 |
_kpsewhich=$BinDir/kpsewhich$ExeExt |
| 13 |
|
| 14 |
test -n "$LN_S" || LN_S="ln -s" # standalone testing |
| 15 |
test "x$LN_S" = 'xln -s' || exit 77 # if symlinks are unsupported, never mind |
| 16 |
|
| 17 |
rm -rf nlinka nlinkc |
| 18 |
(mkdir nlinka nlinkc && mkdir nlinka/nlinksub) || exit 1 |
| 19 |
$LN_S ../../nlinkc nlinka/nlinksub/symlinkdir || exit 77 |
| 20 |
touch nlinka/nlinksub/subfile.tex || exit 1 |
| 21 |
touch nlinkc/throughfile.tex || exit 1 |
| 22 |
|
| 23 |
# We don't need a texmf.cnf for this. |
| 24 |
KPATHSEA_WARNING=0; export KPATHSEA_WARNING |
| 25 |
|
| 26 |
# debugging |
| 27 |
#find nlink\* -type f | sort |
| 28 |
#brokensymlink . |
| 29 |
#ls -lR |
| 30 |
|
| 31 |
# recurse into nlinka subdir. |
| 32 |
TEXINPUTS=nlinka//; export TEXINPUTS |
| 33 |
|
| 34 |
# optimism. |
| 35 |
fail=0 |
| 36 |
|
| 37 |
# |
| 38 |
cnf_line=--cnf-line=texmf_nlink_for_leaf=1 # do the check |
| 39 |
# st_nlink check enabled, file should be found: |
| 40 |
val=`$_kpsewhich $cnf_line subfile.tex` |
| 41 |
if test "$ExeExt" = .exe; then val=`echo $val | sed -e 's/\\r//'`; fi |
| 42 |
# |
| 43 |
# This should find the file, because we always search the directory |
| 44 |
# explicitly given with the // suffix. |
| 45 |
if test x"$val" = xnlinka/nlinksub/subfile.tex; then |
| 46 |
echo "for subfile.tex (with st_nlink check), got expected: $val" |
| 47 |
else |
| 48 |
echo "for subfile.tex (with st_nlink check), failed with: $val" |
| 49 |
fail=1 |
| 50 |
fi |
| 51 |
|
| 52 |
# |
| 53 |
# We can't enable this part of the test, since if the current filesystem |
| 54 |
# is btrfs, or other cases (as noted in elt-dirs.c), Kpathsea will |
| 55 |
# descend anyway, because leaf dirs won't have the traditional semantics |
| 56 |
# of st_nlinks=2. Let's not try to determine that just for the sake of a |
| 57 |
# test; instead, leave it here commented out in case it's needed for |
| 58 |
# future development testing, which can take place on a normal filesystem. |
| 59 |
# |
| 60 |
## st_nlink check enabled, file through symlinked dir should not be found: |
| 61 |
#val=`$_kpsewhich $cnf_line throughfile.tex` |
| 62 |
#if test "$ExeExt" = .exe; then val=`echo $val | sed -e 's/\\r//'`; fi |
| 63 |
## |
| 64 |
## This should not find the file, because with st_nlink, kpse cannot know |
| 65 |
## to descend into the symlinked subdir. |
| 66 |
#if test -z "$val"; then |
| 67 |
# echo "for throughfile.tex, with st_nlink check, not found as expected." |
| 68 |
#else |
| 69 |
# echo "for throughfile.tex, with st_nlink check, failed since found: $val" |
| 70 |
# fail=1 |
| 71 |
#fi |
| 72 |
|
| 73 |
# |
| 74 |
cnf_line=--cnf-line=texmf_nlink_for_leaf=0 # don't do the check |
| 75 |
debug=--debug=-1 # can help to have if something goes wrong |
| 76 |
val=`$_kpsewhich $debug $cnf_line throughfile.tex` |
| 77 |
if test "$ExeExt" = .exe; then val=`echo $val | sed -e 's/\\r//'`; fi |
| 78 |
# |
| 79 |
# without the st_nlink check, we should descend and find the |
| 80 |
# file through the symlinked subdir: |
| 81 |
expect=nlinka/nlinksub/symlinkdir/throughfile.tex |
| 82 |
if test x"$val" = x$expect; then |
| 83 |
echo "for throughfile.tex, without st_nlink check, got expected: $val" |
| 84 |
else |
| 85 |
echo "for throughfile.tex, without st_nlink check, failed with: $val" |
| 86 |
echo " (expected: $expect)" |
| 87 |
fail=1 |
| 88 |
fi |
| 89 |
|
| 90 |
#exit 1 # to force creation of the log for debugging wrong success |
| 91 |
exit $fail |
| 92 |
|
| 93 |
# BTW, to run just this one test: |
| 94 |
# make -C $wk TESTS=tests/cnfnlink.test check |
| 95 |
# where wk=/.../Work/texk/kpathsea |
| 96 |
# and results in $wk/test-suite.log. |