New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File::Copy::mv fails to replicate behavior of Unix mv #8008
Comments
From kynn@panix.comFile::Copy::mv does not preserve the file's mtime across NFS-mounted In the following example, /d00 is an NFS-mounted filesystem, while % rm -f /tmp/foo /d00/home/kynn/bar Now, for comparison, the behavior of mv(1): % rm -f /tmp/foo /d00/home/kynn/bar Perl Info
|
From @schwernOn Mon, Jul 11, 2005 at 10:30:54AM -0700, kynn jones wrote:
You're right. And the problem affects any cross-partition move. mv() The attached patch should fix this by setting the atime and mtime of the -- |
From @schwernFC.patch--- lib/File/Copy.pm 2005/07/12 00:28:38 1.1
+++ lib/File/Copy.pm 2005/07/12 00:31:50
@@ -205,7 +205,17 @@
$tosz2 == $fromsz; # it's all there
($tosz1,$tomt1) = (stat($to))[7,9]; # just in case rename did something
- return 1 if copy($from,$to) && unlink($from);
+
+ {
+ local $@;
+ eval {
+ copy($from,$to) or die;
+ my($atime, $mtime) = (stat($from))[8,9];
+ utime($atime, $mtime, $to);
+ unlink($from) or die;
+ };
+ return 1 unless $@;
+ }
($sts,$ossts) = ($! + 0, $^E + 0);
($tosz2,$tomt2) = ((stat($to))[7,9],0,0) if defined $tomt1;
|
The RT System itself - Status changed from 'new' to 'open' |
From @schwernAttached is a test patch to test File::Copy while copying/moving across It also adds a test for this bug, it checks to make sure the destination |
From @schwernmtime.patch--- lib/File/Copy.t 2005/07/12 01:45:49 1.2
+++ lib/File/Copy.t 2005/07/12 02:13:21
@@ -9,12 +9,23 @@
my $TB = Test::More->builder;
-plan tests => 46;
+plan tests => 48;
+
+# We're going to override rename() later on but Perl has to see an override
+# at compile time to honor it.
+BEGIN { *CORE::GLOBAL::rename = sub { CORE::rename($_[0], $_[1]) }; }
+
use File::Copy;
use Config;
-for (1..2) {
+for my $cross_partition_test (0..1) {
+ {
+ # Simulate a cross-partition copy/move by forcing rename to
+ # fail.
+ no warnings 'redefine';
+ *CORE::GLOBAL::rename = sub { 0 } if $cross_partition_test;
+ }
# First we create a file
open(F, ">file-$$") or die;
@@ -72,12 +83,26 @@
ok !move("file-$$", "copy-$$"), "move on missing file";
ok -e "copy-$$", ' target still there';
+ # Doesn't really matter what time it is as long as its not now.
+ my $time = 1000000000;
+ utime( $time, $time, "copy-$$" );
+
+ # Recheck the mtime rather than rely on utime in case we're on a
+ # system where utime doesn't work or there's no mtime at all.
+ # The destination file will reflect the same difficulties.
+ my $mtime = (stat("copy-$$"))[9];
+
ok move "copy-$$", "file-$$", 'move';
ok -e "file-$$", ' destination exists';
ok !-e "copy-$$", ' source does not';
open(R, "file-$$") or die; $foo = <R>; close(R);
is $foo, "ok\n";
+ my $dest_mtime = (stat("file-$$"))[9];
+ is $dest_mtime, $mtime,
+ "mtime preserved by copy()".
+ ($cross_partition_test ? " while testing cross-partition" : "");
+
copy "file-$$", "lib";
open(R, "lib/file-$$") or die; $foo = <R>; close(R);
is $foo, "ok\n";
@@ -130,7 +155,6 @@
unlink "hardlink-$$";
unlink "file-$$";
}
-
}
|
From @steve-m-hayMichael G Schwern wrote:
Thanks. Applied as change 25120. Radan Computational Ltd. The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email. |
From @steve-m-hayMichael G Schwern via RT wrote:
Thanks - applied as change 25122. Radan Computational Ltd. The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email. |
From @steve-m-hayNow fixed in bleadperl, so should be fixed in 5.8.8, otherwise in 5.10. |
@steve-m-hay - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#36502 (status was 'resolved')
Searchable as RT36502$
The text was updated successfully, but these errors were encountered: