Avoid reading link target when not needed

It is only needed in long listing mode.
This commit is contained in:
Claudio Bley 2018-01-01 22:13:42 +01:00
parent 038c15f53c
commit d12b95da6e
2 changed files with 6 additions and 4 deletions

View file

@ -44,14 +44,14 @@ module ColorLS
private
def init_contents(path)
info = FileInfo.new(path)
info = FileInfo.new(path, link_info = @long)
if info.directory?
@contents = Dir.entries(path)
filter_hidden_contents
@contents.map! { |e| FileInfo.info(File.join(path, e)) }
@contents.map! { |e| FileInfo.new(File.join(path, e), link_info = @long) }
filter_contents if @show
sort_contents if @sort

View file

@ -6,10 +6,11 @@ module ColorLS
attr_reader :stats
attr_reader :name
def initialize(path)
def initialize(path, link_info=true)
@name = File.basename(path)
@stats = File.lstat(path)
return unless @stats.symlink?
return unless link_info && @stats.symlink?
@dead = !File.exist?(path)
@target = File.readlink(path)
end
@ -56,6 +57,7 @@ module ColorLS
@stats.symlink?
end
# target of a symlink (only available for symlinks)
def link_target
@target
end