diff options
author | hut <hut@lavabit.com> | 2009-07-19 23:14:17 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-07-19 23:14:17 +0200 |
commit | 3b20bf79874ec8784799ccd78ac236b9b3838956 (patch) | |
tree | 8c528fb1c866094300bbb5f6d10993f88ee96f06 | |
parent | 7e08f5ad838c644ae08126d075e1316a68f82357 (diff) | |
download | ranger-3b20bf79874ec8784799ccd78ac236b9b3838956.tar.gz |
wrap up many File calls into one File.stat
-rw-r--r-- | code/entry.rb | 29 | ||||
-rw-r--r-- | code/extensions/basic.rb | 14 |
2 files changed, 21 insertions, 22 deletions
diff --git a/code/entry.rb b/code/entry.rb index af1faa83..3b08c54a 100644 --- a/code/entry.rb +++ b/code/entry.rb @@ -38,6 +38,7 @@ class Directory::Entry @readlink = '' @symlink = false @writable = false + @stat = nil @infostring = '' @mimetype = nil @executable = false @@ -50,6 +51,7 @@ class Directory::Entry attr_reader(*%w{ basename mtime rights type path ext mimetype infostring readlink basename size ctime name + stat }) attr_accessor(:marked) @@ -111,38 +113,39 @@ class Directory::Entry @size = 0 @infostring = '' - @exists = File.exists?(@path) + @exists = File.exists?( @path ) if @exists - @writable = File.writable?(@path) - @symlink = File.symlink?(@path) + @stat = File.stat( @path ) + @writable = @stat.writable? + @symlink = File.symlink?( @path ) if @symlink - @readlink = File.readlink(@path) + @readlink = File.readlink( @path ) end - if File.directory?(@path) + if @stat.directory? @type = :dir begin - sz = Dir.entries(@path).size - 2 + sz = Dir.entries( @path ).size - 2 @size = sz rescue sz = "?" end @infostring << "#{sz}" - elsif File.socket?(@path) + elsif @stat.socket? @type = :socket else @type = :file @mimetype = MIMETYPES[@ext] - @size = File.size(@path) - if File.size?(@path) + @size = @stat.size + if @stat.size? @infostring << " #{File.size(@path).bytes 2}" else @infostring << "" end end - @rights = File.modestr(@path) - @executable = File.executable?(@path) - @mtime = File.mtime(@path) - @ctime = File.ctime(@path) + @rights = @stat.modestr + @executable = @stat.executable? + @mtime = @stat.mtime + @ctime = @stat.ctime else if File.symlink?(@path) diff --git a/code/extensions/basic.rb b/code/extensions/basic.rb index f54c3d75..c07402d7 100644 --- a/code/extensions/basic.rb +++ b/code/extensions/basic.rb @@ -135,7 +135,7 @@ class Dir end end -class File +class File::Stat MODES_HASH = { '0' => '---', '1' => '--x', @@ -146,20 +146,16 @@ class File '6' => 'rw-', '7' => 'rwx' } - def self.modestr(f) - unless exists?(f) - return '----------' - end - - if symlink?(f) + def modestr + if symlink? result = 'l' - elsif directory?(f) + elsif directory? result = 'd' else result = '-' end - s = ("%o" % File.stat(f).mode)[-3..-1] + s = ("%o" % mode)[-3..-1] for m in s.each_char result << MODES_HASH[m] end |