Open p5pRT opened 14 years ago
File::Copy::move silently fails to move a file if the destination path happens to be a hardlink to the same file as the source path. The effetc is that it returns success\, but both source and destination paths still exist.
The problem is likely that it uses rename but doesn't check whether rename actually does something (rename simply returns sucecss if source and destination refer to the same file).
On Sun Dec 06 16:58:15 2009\, perlbug@plan9.de wrote:
File::Copy::move silently fails to move a file if the destination path happens to be a hardlink to the same file as the source path. The effetc is that it returns success\, but both source and destination paths still exist.
The problem is likely that it uses rename but doesn't check whether rename actually does something (rename simply returns sucecss if source and destination refer to the same file).
To my surprise\, I get different results on different OSes when I try to reproduce this phenomenon. In my case\, the two OSes are Linux and Darwin.
On both OSes: ### $ cat alpha.txt $class = { alpha => 'beta'\, gamma => 'delta'\, epsilon => 'zeta'\, };
$ ln -v alpha.txt tmp/beta.txt tmp/beta.txt => alpha.txt
$ cat tmp/beta.txt $class = { alpha => 'beta'\, gamma => 'delta'\, epsilon => 'zeta'\, }; ###
On Linux:
### $ perl -MFile::Copy -e 'move "./alpha.txt" => "tmp/beta.txt" or die "Unable to move: $!";'
$ cat alpha.txt $class = { alpha => 'beta'\, gamma => 'delta'\, epsilon => 'zeta'\, };
$ cat tmp/beta.txt $class = { alpha => 'beta'\, gamma => 'delta'\, epsilon => 'zeta'\, }; ###
Corroborates problem reported by original poster.
However\, on Darwin ...
### $ perl -MFile::Copy -e 'move "./alpha.txt" => "tmp/beta.txt" or die "Unable to move: $!";'
$ cat alpha.txt cat: alpha.txt: No such file or directory
$ cat tmp/beta.txt $class = { alpha => 'beta'\, gamma => 'delta'\, epsilon => 'zeta'\, }; ###
... which does what I think original poster feels should happen.
Am I misunderstanding something about the problem -- or is this a genuine difference between the two OSes?
Thank you very much. Jim Keenan
The RT System itself - Status changed from 'new' to 'open'
On Tue\, Nov 29\, 2011 at 04:27:53PM -0800\, James E Keenan via RT \perlbug\-followup@​perl\.org wrote:
To my surprise\, I get different results on different OSes when I try to reproduce this phenomenon. In my case\, the two OSes are Linux and Darwin.
Just guessing\, but thats probably because linux implements posix rename() accurately\, while some versions of os x are only posix-certified and far from actually implementing it :)
The relevant posix spec section is\, as I know nowadays:
If the old argument and the new argument resolve to the same existing file\, rename() shall return successfully and perform no other action.
that is\, if both old and new are hardlinks to the same file\, rename just does nothing\, leaving both intact\, reporting success. this is not a bug in the posix spec either\, it's really meant to act like that.
silly - one would expect rename to work on filenames.
In any case\, since rename is "just" an optimiation\, File::Copy ought to detect that (coreutils mv does it for example\, at least when not posixly correct). Maybe unlinking the from after a successfull rename might do the trick - I'd rather not think too hard about it.
In any case\, rename returning success on a posix system does not mean the old name has been removed\, and thats likely whats happening.
-- The choice of a Deliantra\, the free code+content MORPG -----==- _GNU_ http://www.deliantra.net ----==-- _ generation ---==---(_)__ __ ____ __ Marc Lehmann --==---/ / _ \/ // /\ \/ / schmorp@schmorp.de -=====/_/_//_/\_\,_/ /_/\_\
Migrated from rt.perl.org#71082 (status was 'open')
Searchable as RT71082$