[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Possible bug in readlink, canonicalize fails.
From: |
mpb |
Subject: |
Possible bug in readlink, canonicalize fails. |
Date: |
Fri, 21 Sep 2007 00:42:36 -0700 |
Hi,
I believe the following script demonstrates that readlink cannot
always canonicalize paths. It may be possible to create a simpler
demonstration of the bug, but I could not trivially do so.
Thanks!
-mpb
----------------------------------
#! /bin/bash
# Clean up previous demonstations of the bug.
if [ -a /tmp/a0 ]; then rm -r /tmp/a0; fi
if [ -a /tmp/c0 ]; then rm -r /tmp/c0; fi
# Create 3 directories.
mkdir -p /tmp/a0/a1/a2/a3/a4/a5
mkdir -p /tmp/a0/a1/a2/b3/b4
mkdir -p /tmp/c0
# Create 1 file.
echo 'I am a6.' > /tmp/a0/a1/a2/a3/a4/a5/a6
# Create 3 symbolic links inside those directories.
ln -s a1/a2 /tmp/a0/a2
ln -s /tmp/a0/a2/b3 /tmp/c0/b3
ln -s /tmp/a0/a2/a3/a4/a5 /tmp/c0/b3/b4/a5
# Show what we have created.
find /tmp/a0 /tmp/c0
# Specify a convoluted (but valid) path to the file a6.
path=/tmp/c0/b3/b4/a5/a6
# Look! The file exists at $path!
echo
echo The file exists ...
ls -l $path
cat $path
# But readlink cannot canonicalize it!
echo
echo ... but readlink cannot canonicalize it!
readlink -f $path
echo "readlink exit status: $?"
readlink -e $path
echo "readlink exit status: $?"
readlink -m $path
echo "readlink exit status: $?"
# I am running: "readlink (GNU coreutils) 6.9"
echo
readlink --version
--------------------------------------------------
When I run the script, I get the following output:
$ bash bug.sh
/tmp/a0
/tmp/a0/a1
/tmp/a0/a1/a2
/tmp/a0/a1/a2/a3
/tmp/a0/a1/a2/a3/a4
/tmp/a0/a1/a2/a3/a4/a5
/tmp/a0/a1/a2/a3/a4/a5/a6
/tmp/a0/a1/a2/b3
/tmp/a0/a1/a2/b3/b4
/tmp/a0/a1/a2/b3/b4/a5
/tmp/a0/a2
/tmp/c0
/tmp/c0/b3
The file exists ...
-rw-r--r-- 1 asterisk asterisk 9 Sep 21 00:39 /tmp/c0/b3/b4/a5/a6
I am a6.
... but readlink cannot canonicalize it!
readlink exit status: 1
readlink exit status: 1
/tmp/a0/a2/a3/a4/a5/a6
readlink exit status: 0
readlink (GNU coreutils) 6.9
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.
Written by Dmitry V. Levin.
- Possible bug in readlink, canonicalize fails.,
mpb <=