mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-19 05:31:23 +02:00
Avoid reading link target when not needed
It is only needed in long listing mode.
This commit is contained in:
parent
038c15f53c
commit
d12b95da6e
2 changed files with 6 additions and 4 deletions
|
@ -44,14 +44,14 @@ module ColorLS
|
||||||
private
|
private
|
||||||
|
|
||||||
def init_contents(path)
|
def init_contents(path)
|
||||||
info = FileInfo.new(path)
|
info = FileInfo.new(path, link_info = @long)
|
||||||
|
|
||||||
if info.directory?
|
if info.directory?
|
||||||
@contents = Dir.entries(path)
|
@contents = Dir.entries(path)
|
||||||
|
|
||||||
filter_hidden_contents
|
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
|
filter_contents if @show
|
||||||
sort_contents if @sort
|
sort_contents if @sort
|
||||||
|
|
|
@ -6,10 +6,11 @@ module ColorLS
|
||||||
attr_reader :stats
|
attr_reader :stats
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
def initialize(path)
|
def initialize(path, link_info=true)
|
||||||
@name = File.basename(path)
|
@name = File.basename(path)
|
||||||
@stats = File.lstat(path)
|
@stats = File.lstat(path)
|
||||||
return unless @stats.symlink?
|
|
||||||
|
return unless link_info && @stats.symlink?
|
||||||
@dead = !File.exist?(path)
|
@dead = !File.exist?(path)
|
||||||
@target = File.readlink(path)
|
@target = File.readlink(path)
|
||||||
end
|
end
|
||||||
|
@ -56,6 +57,7 @@ module ColorLS
|
||||||
@stats.symlink?
|
@stats.symlink?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# target of a symlink (only available for symlinks)
|
||||||
def link_target
|
def link_target
|
||||||
@target
|
@target
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue