#!/bin/sh -vx # $Id: cnfnlink.test 76831 2025-11-11 23:41:11Z karl $ # Copyright 2025 Karl Berry # You may freely use, modify and/or distribute this file. # # Test configuration value for enabling/disabling the check for # st_nlink=2 to determine leaf directories. For the problem reports that # motivated this, see the "Subdirectory expansion" node in the Kpathsea manual. BinDir=${BinDir:-.} ExeExt=${ExeExt:-} _kpsewhich=$BinDir/kpsewhich$ExeExt test -n "$LN_S" || LN_S="ln -s" # standalone testing test "x$LN_S" = 'xln -s' || exit 77 # if symlinks are unsupported, never mind rm -rf nlinka nlinkc (mkdir nlinka nlinkc && mkdir nlinka/nlinksub) || exit 1 $LN_S ../../nlinkc nlinka/nlinksub/symlinkdir || exit 77 touch nlinka/nlinksub/subfile.tex || exit 1 touch nlinkc/throughfile.tex || exit 1 # We don't need a texmf.cnf for this. KPATHSEA_WARNING=0; export KPATHSEA_WARNING # debugging #find nlink\* -type f | sort #brokensymlink . #ls -lR # recurse into nlinka subdir. TEXINPUTS=nlinka//; export TEXINPUTS # optimism. fail=0 # cnf_line=--cnf-line=texmf_nlink_for_leaf=1 # do the check # st_nlink check enabled, file should be found: val=`$_kpsewhich $cnf_line subfile.tex` if test "$ExeExt" = .exe; then val=`echo $val | sed -e 's/\\r//'`; fi # # This should find the file, because we always search the directory # explicitly given with the // suffix. if test x"$val" = xnlinka/nlinksub/subfile.tex; then echo "for subfile.tex (with st_nlink check), got expected: $val" else echo "for subfile.tex (with st_nlink check), failed with: $val" fail=1 fi # # We can't enable this part of the test, since if the current filesystem # is btrfs, or other cases (as noted in elt-dirs.c), Kpathsea will # descend anyway, because leaf dirs won't have the traditional semantics # of st_nlinks=2. Let's not try to determine that just for the sake of a # test; instead, leave it here commented out in case it's needed for # future development testing, which can take place on a normal filesystem. # ## st_nlink check enabled, file through symlinked dir should not be found: #val=`$_kpsewhich $cnf_line throughfile.tex` #if test "$ExeExt" = .exe; then val=`echo $val | sed -e 's/\\r//'`; fi ## ## This should not find the file, because with st_nlink, kpse cannot know ## to descend into the symlinked subdir. #if test -z "$val"; then # echo "for throughfile.tex, with st_nlink check, not found as expected." #else # echo "for throughfile.tex, with st_nlink check, failed since found: $val" # fail=1 #fi # cnf_line=--cnf-line=texmf_nlink_for_leaf=0 # don't do the check debug=--debug=-1 # can help to have if something goes wrong val=`$_kpsewhich $debug $cnf_line throughfile.tex` if test "$ExeExt" = .exe; then val=`echo $val | sed -e 's/\\r//'`; fi # # without the st_nlink check, we should descend and find the # file through the symlinked subdir: expect=nlinka/nlinksub/symlinkdir/throughfile.tex if test x"$val" = x$expect; then echo "for throughfile.tex, without st_nlink check, got expected: $val" else echo "for throughfile.tex, without st_nlink check, failed with: $val" echo " (expected: $expect)" fail=1 fi #exit 1 # to force creation of the log for debugging wrong success exit $fail # BTW, to run just this one test: # make -C $wk TESTS=tests/cnfnlink.test check # where wk=/.../Work/texk/kpathsea # and results in $wk/test-suite.log.