2004-04-07 17:41:05

by Martin Rode

[permalink] [raw]
Subject: cp fails in this symlink case, kernel 2.4.25, reiserfs + ext2

Dear developers,

After 10 years with linux I am happy I can report something :-).

I don't know 100% if is a bug, but I think it is.

The example below fails on reiserfs as well as on ext2 for me. I dont
think it should fail, or am I missing something?

Please cc me personally, I am not a subscriber.

Kernel testet: 2.4.[25|19]
Filesystems testet: reiserfs, ext2

Take Care,
Martin


How to reproduce:
-----------------

In any directory try this:

1) mkdir -p alpha/gamma beta
2) (cd alpha; ln -s ../beta .; ln -s gamma latest;)
3) echo "Test" > alpha/gamma/myfile

4) Check
apu:/home/martin/tmp/bug# find -exec file {} \;
.: directory
./alpha: directory
./alpha/gamma: directory
./alpha/gamma/myfile: ASCII text
./alpha/beta: symbolic link to `../beta'
./alpha/latest: symbolic link to `gamma'
./beta: directory

5) cp fails
apu:/home/martin/tmp/bug# (cd alpha/beta; cp ../latest/myfile .)
cp: cannot stat `../latest/myfile': No such file or directory

6) cp ok
apu:/home/martin/tmp/bug# (cd alpha/; cp latest/myfile beta && echo
"ok")
ok




2004-04-07 19:16:25

by Dave Kleikamp

[permalink] [raw]
Subject: Re: cp fails in this symlink case, kernel 2.4.25, reiserfs + ext2

On Wed, 2004-04-07 at 12:35, Martin Rode wrote:
> 5) cp fails
> apu:/home/martin/tmp/bug# (cd alpha/beta; cp ../latest/myfile .)
> cp: cannot stat `../latest/myfile': No such file or directory

When you cd to alpha/beta, your current directory is really
.../tmp/bug/beta. Your shell may remember that you got there through
the symlink in alpha, but cp will follow .., which is really bug.

--
David Kleikamp
IBM Linux Technology Center

2004-04-08 08:03:11

by Martin Rode

[permalink] [raw]
Subject: Re: cp fails in this symlink case, kernel 2.4.25, reiserfs + ext2

On Wed, 2004-04-07 at 21:16, Dave Kleikamp wrote:
> On Wed, 2004-04-07 at 12:35, Martin Rode wrote:
> > 5) cp fails
> > apu:/home/martin/tmp/bug# (cd alpha/beta; cp ../latest/myfile .)
> > cp: cannot stat `../latest/myfile': No such file or directory
>
> When you cd to alpha/beta, your current directory is really
> .../tmp/bug/beta. Your shell may remember that you got there through
> the symlink in alpha, but cp will follow .., which is really bug.

Bug in "cp", "bash" or in the kernel fs-layer?

Martin

--
Zeroscale GmbH & Co.
Game Development

2004-04-08 09:24:19

by Andreas Schwab

[permalink] [raw]
Subject: Re: cp fails in this symlink case, kernel 2.4.25, reiserfs + ext2

Martin Rode <[email protected]> writes:

> On Wed, 2004-04-07 at 21:16, Dave Kleikamp wrote:
>> On Wed, 2004-04-07 at 12:35, Martin Rode wrote:
>> > 5) cp fails
>> > apu:/home/martin/tmp/bug# (cd alpha/beta; cp ../latest/myfile .)
>> > cp: cannot stat `../latest/myfile': No such file or directory
>>
>> When you cd to alpha/beta, your current directory is really
>> .../tmp/bug/beta. Your shell may remember that you got there through
>> the symlink in alpha, but cp will follow .., which is really bug.
>
> Bug in "cp", "bash" or in the kernel fs-layer?

Neither.

Andreas.

--
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux AG, Maxfeldstra?e 5, 90409 N?rnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."

2004-04-08 21:19:09

by Michael Driscoll

[permalink] [raw]
Subject: Re: cp fails in this symlink case, kernel 2.4.25, reiserfs + ext2

On Thursday 08 April 2004 01:56, Martin Rode wrote:
> On Wed, 2004-04-07 at 21:16, Dave Kleikamp wrote:
> > When you cd to alpha/beta, your current directory is really
> > .../tmp/bug/beta. Your shell may remember that you got there through
> > the symlink in alpha, but cp will follow .., which is really bug.
>
> Bug in "cp", "bash" or in the kernel fs-layer?
>
> Martin

Call it a bug in POSIX, if anything ;)

Remember that '..' is a directory entry in the filesystem, not a construct of
your shell. Specifically, it is a pointer to the parent directory of the
directory in which it is found.

Usually /a/b/../c is the same as a/c, but not if /a/b is a symlink to /d as in
this case.

--
Michael Driscoll, [email protected]
"A noble spirit embiggens the smallest man" -- J. Springfield

2004-04-10 19:53:09

by Andries Brouwer

[permalink] [raw]
Subject: Re: cp fails in this symlink case, kernel 2.4.25, reiserfs + ext2

On Thu, Apr 08, 2004 at 11:24:14AM +0200, Andreas Schwab wrote:

> >> > 5) cp fails
> >> > apu:/home/martin/tmp/bug# (cd alpha/beta; cp ../latest/myfile .)
> >> > cp: cannot stat `../latest/myfile': No such file or directory
> >>
> >> When you cd to alpha/beta, your current directory is really
> >> .../tmp/bug/beta. Your shell may remember that you got there through
> >> the symlink in alpha, but cp will follow .., which is really bug.
> >
> > Bug in "cp", "bash" or in the kernel fs-layer?
>
> Neither.

POSIX is seriously broken here. It is terrible to have a system
where "cd .." does not go to the directory that is listed by "ls ..".

Thus, one should always set -o physical.

(We should have had a command "cd.." to go back to where we came from,
distinct from "cd ..".)

But also bash is broken and violates POSIX:
% pwd
/foo
% mkdir abc
% cd abc
% pwd
/foo/abc
% mv ../abc ../qqq
% /bin/pwd
/foo/qqq
% pwd
/foo/abc
% pwd -L
/foo/abc
% pwd -P
%

We see two bugs: "pwd -P" gives no output at all, and "pwd"
gives the wrong output.

POSIX says:
-L If the PWD environment variable contains an abso-
lute pathname of the current directory that does
not contain the filenames dot or dot-dot, pwd shall
write this pathname to standard output. Otherwise,
the -L option shall behave as the -P option.

So, in the situation where PWD contains /foo/abc but that is
not an absolute pathname of the current directory, the output
must be /foo/qqq and not $PWD.

Andries