Class: LogStash::Setting::WritableDirectory
Instance Attribute Summary
#default, #name
Instance Method Summary
collapse
#==, #reset, #set, #set?, #strict?, #to_hash, #validate_value
Constructor Details
#initialize(name, default = nil, strict = false) ⇒ WritableDirectory
438
439
440
|
# File 'lib/logstash/settings.rb', line 438
def initialize(name, default=nil, strict=false)
super(name, ::String, default, strict)
end
|
Instance Method Details
#validate(path) ⇒ Object
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
# File 'lib/logstash/settings.rb', line 442
def validate(path)
super(path)
if ::File.directory?(path)
if !::File.writable?(path)
raise ::ArgumentError.new("Path \"#{path}\" must be a writable directory. It is not writable.")
end
elsif ::File.symlink?(path)
raise ::ArgumentError.new("Path \"#{path}\" must be a writable directory. It cannot be a symlink.")
elsif ::File.exist?(path)
raise ::ArgumentError.new("Path \"#{path}\" must be a writable directory. It is not a directory.")
else
parent = ::File.dirname(path)
if !::File.writable?(parent)
raise ::ArgumentError.new("Path \"#{path}\" does not exist and I cannot create it because the parent path \"#{parent}\" is not writable.")
end
end
true
end
|
#value ⇒ Object
466
467
468
469
470
471
472
473
474
475
476
477
478
479
|
# File 'lib/logstash/settings.rb', line 466
def value
super.tap do |path|
if !::File.directory?(path)
begin
logger.info("Creating directory", setting: name, path: path)
::FileUtils.mkdir_p(path)
rescue => e
raise ::ArgumentError.new("Path \"#{path}\" does not exist, and I failed trying to create it: #{e.class.name} - #{e}")
end
end
end
end
|