kenahoo / Path-Class

Cross-platform path specification manipulation
http://search.cpan.org/dist/Path-Class/
15 stars 28 forks source link

file->touch broken on Linux cifs mount #23

Closed mrdvt92 closed 10 years ago

mrdvt92 commented 11 years ago

Also logged as RT 88389 https://rt.cpan.org/Ticket/Display.html?id=88389

file->touch will create a file but will not update the file times like the Linux touch command.

$ perl -MPath::Class=file -e 'print Path::Class->VERSION, "\n"' 0.16

I reviewed the change log and there have been no changes to touch since 0.13

$ mount //server/path on /mnt/path type cifs (rw,mand) /dev/mapper/VG00-LV00 on / type ext3 (rw)

On ext3 partition file->touch works correctly

$ stat y stat: cannot stat `y': No such file or directory

$ perl -MPath::Class=file -e 'file("y")->touch' $ stat y File: `y' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd04h/64772d Inode: 149525 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 500/ mdavis) Gid: ( 500/ mdavis) Access: 2013-09-03 14:43:12.000000000 +0000 Modify: 2013-09-03 14:43:12.000000000 +0000 Change: 2013-09-03 14:43:12.000000000 +0000

$ perl -MPath::Class=file -e 'file("y")->touch' $ stat y File: `y' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd04h/64772d Inode: 149525 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 500/ mdavis) Gid: ( 500/ mdavis) Access: 2013-09-03 14:43:15.000000000 +0000 Modify: 2013-09-03 14:43:15.000000000 +0000 Change: 2013-09-03 14:43:15.000000000 +0000

On cifs partition it fails to "touch" on an existing file

$ stat x stat: cannot stat `x': No such file or directory

$ perl -MPath::Class=file -e 'file("x")->touch' $ stat x File: `x' Size: 0 Blocks: 0 IO Block: 16384 regular empty file Device: 19h/25d Inode: 17732923532791182 Links: 1 Access: (0775/-rwxrwxr-x) Uid: ( 0/ root) Gid: ( 500/ mdavis) Access: 2013-09-03 14:45:07.666404500 +0000 Modify: 2013-09-03 14:45:07.666404500 +0000 Change: 2013-09-03 14:45:07.666404500 +0000

created correctly with correct times

$ perl -MPath::Class=file -e 'file("x")->touch' $ stat x File: `x' Size: 0 Blocks: 0 IO Block: 16384 regular empty file Device: 19h/25d Inode: 17732923532791182 Links: 1 Access: (0775/-rwxrwxr-x) Uid: ( 0/ root) Gid: ( 500/ mdavis) Access: 2013-09-03 14:45:07.666404500 +0000 Modify: 2013-09-03 14:45:07.666404500 +0000 Change: 2013-09-03 14:45:07.666404500 +0000

BUG times were not updated!!!

$ touch x $ stat x File: `x' Size: 0 Blocks: 0 IO Block: 16384 regular empty file Device: 19h/25d Inode: 17732923532791182 Links: 1 Access: (0775/-rwxrwxr-x) Uid: ( 0/ root) Gid: ( 500/ mdavis) Access: 2013-09-03 14:45:28.141687900 +0000 Modify: 2013-09-03 14:45:28.141687900 +0000 Change: 2013-09-03 14:45:28.141687900 +0000

Linux touch commands works correctly

Thanks, Mike

mrdvt92

kenahoo commented 11 years ago

What if you try the following patch, does it work then?

diff --git a/lib/Path/Class/File.pm b/lib/Path/Class/File.pm
index 6bf63f1..432922a 100644
--- a/lib/Path/Class/File.pm
+++ b/lib/Path/Class/File.pm
@@ -71,8 +71,7 @@ sub opena { $_[0]->open('a') or croak "Can't append to $_[0]: $!" }
 sub touch {
   my $self = shift;
   if (-e $self) {
-    my $now = time();
-    utime $now, $now, $self;
+    utime undef, undef, $self;
   } else {
     $self->openw;
   }
kenahoo commented 10 years ago

I released this as part of version 0.33. Closing the ticket.