Module: Sprinkle::Verifiers::File

Defined in:
lib/sprinkle/verifiers/file.rb

Overview

File Verifier

Contains a verifier to check the existance of a file.

Example Usage

verify { has_file '/etc/apache2/apache2.conf' }

verify { file_contains '/etc/apache2/apache2.conf', 'mod_gzip'}

Instance Method Summary collapse

Instance Method Details

#file_contains(path, text) ⇒ Object


44
45
46
# File 'lib/sprinkle/verifiers/file.rb', line 44

def file_contains(path, text)
  @commands << "grep '#{text}' #{path}"
end

#has_directory(dir) ⇒ Object

Tests that the directory dir exists.


22
23
24
# File 'lib/sprinkle/verifiers/file.rb', line 22

def has_directory(dir)
  test "-d #{dir}"
end

#has_file(path) ⇒ Object

tests that the file path exists


17
18
19
# File 'lib/sprinkle/verifiers/file.rb', line 17

def has_file(path)
  test "-f #{path}"
end

Checks that symlink is a symbolic link. If file is given, it checks that symlink points to file


28
29
30
31
32
33
34
# File 'lib/sprinkle/verifiers/file.rb', line 28

def has_symlink(symlink, file = nil)
  if file.nil?
    test "-L #{symlink}"
  else
    test "'#{file}' = `readlink #{symlink}`"
  end
end

#matches_local(localfile, remotefile, mode = nil) ⇒ Object


54
55
56
57
58
59
# File 'lib/sprinkle/verifiers/file.rb', line 54

def matches_local(localfile, remotefile, mode=nil)
  raise "Couldn't find local file #{localfile}" unless ::File.exists?(localfile)
  require 'digest/md5'
  local = Digest::MD5.hexdigest(::File.read(localfile))
  md5_of_file remotefile, local
end

#md5_of_file(path, md5) ⇒ Object


40
41
42
# File 'lib/sprinkle/verifiers/file.rb', line 40

def md5_of_file(path, md5)
  test "\"`#{sudo_cmd}md5sum #{path} | cut -f1 -d' '`\" = \"#{md5}\""
end

#no_file(path) ⇒ Object


36
37
38
# File 'lib/sprinkle/verifiers/file.rb', line 36

def no_file(path)
  test "! -f #{path}"
end

#user_present(username) ⇒ Object

TODO: remove 0.9


49
50
51
52
# File 'lib/sprinkle/verifiers/file.rb', line 49

def user_present(username) 
  ActiveSupport::Deprecation.warn("user_present is depreciated.  Use has_user instead.")  
  has_user username
end