Skip to content

Commit

Permalink
Fix exception when permission denied on symlinks (#340)
Browse files Browse the repository at this point in the history
Fix exception when permission denied on symlinks
  • Loading branch information
avdv authored Jan 31, 2020
2 parents 4befc68 + 6b2cbdc commit e4a8098
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/colorls/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ def long_info(content)
def symlink_info(content)
return '' unless @long && content.symlink?

link_info = " ⇒ #{content.link_target}"
target = content.link_target.nil? ? '…' : content.link_target
link_info = " ⇒ #{target}"
if content.dead?
"#{link_info} [Dead link]".colorize(@colors[:dead_link])
else
Expand Down
14 changes: 10 additions & 4 deletions lib/colorls/fileinfo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ def initialize(path, link_info=true)
@name = File.basename(path)
@stats = File.lstat(path)

return unless link_info && @stats.symlink?

@dead = !File.exist?(path)
@target = File.readlink(path)
handle_symlink(path) if link_info && @stats.symlink?
end

def self.info(path)
Expand Down Expand Up @@ -58,5 +55,14 @@ def to_s
end

def_delegators :@stats, :directory?, :socket?, :chardev?, :symlink?, :blockdev?, :mtime, :nlink, :size, :owned?

private

def handle_symlink(path)
@target = File.readlink(path)
@dead = !File.exist?(path)
rescue SystemCallError => e
STDERR.puts "cannot read symbolic link: #{e}"
end
end
end

0 comments on commit e4a8098

Please sign in to comment.