2015-09-08 10:59:36 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
require 'shellwords'
|
|
|
|
|
|
|
|
class Vulcano::Plugins::Backend
|
2015-09-29 17:18:48 +00:00
|
|
|
autoload :Stat, 'vulcano/plugins/backend_stat'
|
|
|
|
|
2015-09-08 10:59:36 +00:00
|
|
|
class LinuxFile < FileCommon
|
2015-09-16 09:22:40 +00:00
|
|
|
attr_reader :path
|
2015-09-08 10:59:36 +00:00
|
|
|
def initialize(backend, path)
|
|
|
|
@backend = backend
|
|
|
|
@path = path
|
|
|
|
@spath = Shellwords.escape(@path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def content
|
2015-09-24 01:32:36 +00:00
|
|
|
return @content if @content_fetched
|
|
|
|
@content = @backend.run_command(
|
2015-09-08 10:59:36 +00:00
|
|
|
"cat #{@spath} 2>/dev/null || echo -n").stdout
|
2015-09-24 01:32:36 +00:00
|
|
|
@content_fetched = true
|
|
|
|
return @content unless @content.empty?
|
|
|
|
@content = nil if directory? or size.nil? or size > 0
|
|
|
|
@content
|
2015-09-08 10:59:36 +00:00
|
|
|
end
|
|
|
|
|
2015-09-18 10:35:32 +00:00
|
|
|
def exist?
|
|
|
|
@exist ||= (
|
2015-09-08 10:59:36 +00:00
|
|
|
@backend.
|
|
|
|
run_command("test -e #{@spath}").
|
|
|
|
exit_status == 0
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2015-09-15 10:28:36 +00:00
|
|
|
def link_target
|
|
|
|
return @link_target unless @link_target.nil?
|
|
|
|
return @link_target = nil if link_path.nil?
|
|
|
|
@link_target = @backend.file(link_path)
|
|
|
|
end
|
|
|
|
|
2015-09-15 10:18:07 +00:00
|
|
|
def link_path
|
|
|
|
return nil unless symlink?
|
|
|
|
@link_path ||= (
|
2015-09-08 10:59:36 +00:00
|
|
|
@backend.
|
2015-09-10 11:00:04 +00:00
|
|
|
run_command("readlink #{@spath}").stdout.chomp
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def mounted?
|
|
|
|
@mounted ||= (
|
|
|
|
!@backend.
|
|
|
|
run_command("mount | grep -- ' on #{@spath}'").
|
|
|
|
stdout.empty?
|
2015-09-08 10:59:36 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
%w{
|
2015-09-15 09:34:09 +00:00
|
|
|
type mode owner group mtime size selinux_label
|
2015-09-08 10:59:36 +00:00
|
|
|
}.each do |field|
|
|
|
|
define_method field.to_sym do
|
|
|
|
stat[field.to_sym]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-15 09:34:09 +00:00
|
|
|
def product_version
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_version
|
|
|
|
nil
|
|
|
|
end
|
2015-09-08 10:59:36 +00:00
|
|
|
|
|
|
|
def stat
|
2015-09-29 17:18:48 +00:00
|
|
|
return @stat if defined?(@stat)
|
|
|
|
@stat = ::Vulcano::Plugins::Backend::Stat.stat(@spath, @backend)
|
2015-09-16 19:02:15 +00:00
|
|
|
end
|
2015-09-08 10:59:36 +00:00
|
|
|
end
|
|
|
|
end
|