开发者

Any way to get dir entries without changing atime in Ruby?

It looks Dir.entries("dir") updates the dir's atime on Linux.

irb(main):042:0> File::Stat.new("/tmp/tmp2").atime
=> Thu Aug 25 09:16:36 -0700 2011
irb(main):043:0> File::Stat.new("/tmp/tmp2").atime
=> Thu Aug 开发者_如何学C25 09:16:36 -0700 2011
irb(main):044:0> Dir.entries("/tmp/tmp2")
=> ["file1", "..", ".", "dir1"]
irb(main):045:0> File::Stat.new("/tmp/tmp2").atime
=> Thu Aug 25 09:16:49 -0700 2011

Is it possible to get the dir entries without changing the atime of itself in Ruby?


There's no way to do it in Ruby, or even in general. Reading any file or directory, by any method, will always update its atime. (Unless the whole filesystem is set to not use atimes with a mount flag, like noatime or relatime.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜