Module: Fluent::FileUtil

Defined in:
lib/fluent/plugin/file_util.rb

Class Method Summary collapse

Class Method Details

.writable?(path) ⇒ Boolean

Check file is writable if file exists Check directory is writable if file does not exist

Parameters:

  • path (String)

    File path

Returns:

  • (Boolean)

    file is writable or not



24
25
26
27
28
29
30
31
# File 'lib/fluent/plugin/file_util.rb', line 24

def writable?(path)
  return false if File.directory?(path)
  return File.writable?(path) if File.exist?(path)

  dirname = File.dirname(path)
  return false if !File.directory?(dirname)
  File.writable?(dirname)
end

.writable_p?(path) ⇒ Boolean

Check file is writable in conjunction wtih mkdir_p(dirname(path))

Parameters:

  • path (String)

    File path

Returns:

  • (Boolean)

    file writable or not



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fluent/plugin/file_util.rb', line 38

def writable_p?(path)
  return false if File.directory?(path)
  return File.writable?(path) if File.exist?(path)

  dirname = File.dirname(path)
  until File.exist?(dirname)
    dirname = File.dirname(dirname)
  end

  return false if !File.directory?(dirname)
  File.writable?(dirname)
end