about summary refs log tree commit diff stats
path: root/code/entry.rb
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-07-19 23:14:17 +0200
committerhut <hut@lavabit.com>2009-07-19 23:14:17 +0200
commit3b20bf79874ec8784799ccd78ac236b9b3838956 (patch)
tree8c528fb1c866094300bbb5f6d10993f88ee96f06 /code/entry.rb
parent7e08f5ad838c644ae08126d075e1316a68f82357 (diff)
downloadranger-3b20bf79874ec8784799ccd78ac236b9b3838956.tar.gz
wrap up many File calls into one File.stat
Diffstat (limited to 'code/entry.rb')
-rw-r--r--code/entry.rb29
1 files changed, 16 insertions, 13 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)