Class: Specinfra::Command::Darwin::Base::File

Inherits:
Base::File show all
Defined in:
lib/specinfra/command/darwin/base/file.rb

Class Method Summary collapse

Methods inherited from Base::File

change_group, change_mode, change_owner, check_contains, check_contains_lines, check_contains_with_fixed_strings, check_contains_with_regexp, check_contains_within, check_exists, check_is_block_device, check_is_character_device, check_is_directory, check_is_file, check_is_link, check_is_mounted, check_is_pipe, check_is_socket, check_is_symlink, copy, create_as_directory, download, get_content, get_link_target, get_mtime, get_size, link_to, move, remove

Methods inherited from Base

create, escape

Class Method Details

.check_has_mode(file, mode) ⇒ Object



19
20
21
22
# File 'lib/specinfra/command/darwin/base/file.rb', line 19

def check_has_mode(file, mode)
  regexp = "^#{mode}$"
  "stat -f%Lp #{escape(file)} | grep -- #{escape(regexp)}"
end

.check_is_accessible_by_user(file, user, access) ⇒ Object



3
4
5
# File 'lib/specinfra/command/darwin/base/file.rb', line 3

def check_is_accessible_by_user(file, user, access)
  "sudo -u #{user} -s /bin/test -#{access} #{file}"
end

.check_is_grouped(file, group) ⇒ Object



29
30
31
32
# File 'lib/specinfra/command/darwin/base/file.rb', line 29

def check_is_grouped(file, group)
  regexp = "^#{group}$"
  "stat -f %Sg #{escape(file)} | grep -- #{escape(regexp)}"
end

.check_is_linked_to(link, target) ⇒ Object



15
16
17
# File 'lib/specinfra/command/darwin/base/file.rb', line 15

def check_is_linked_to(link, target)
  "stat -f %Y #{escape(link)} | grep -- #{escape(target)}"
end

.check_is_owned_by(file, owner) ⇒ Object



24
25
26
27
# File 'lib/specinfra/command/darwin/base/file.rb', line 24

def check_is_owned_by(file, owner)
  regexp = "^#{owner}$"
  "stat -f %Su #{escape(file)} | grep -- #{escape(regexp)}"
end

.get_md5sum(file) ⇒ Object



7
8
9
# File 'lib/specinfra/command/darwin/base/file.rb', line 7

def get_md5sum(file)
  "openssl md5 #{escape(file)} | cut -d'=' -f2 | cut -c 2-"
end

.get_mode(file) ⇒ Object



34
35
36
# File 'lib/specinfra/command/darwin/base/file.rb', line 34

def get_mode(file)
  "stat -f%Lp #{escape(file)}"
end

.get_owner_group(file) ⇒ Object



42
43
44
# File 'lib/specinfra/command/darwin/base/file.rb', line 42

def get_owner_group(file)
  "stat -f %Sg #{escape(file)}"
end

.get_owner_user(file) ⇒ Object



38
39
40
# File 'lib/specinfra/command/darwin/base/file.rb', line 38

def get_owner_user(file)
  "stat -f %Su #{escape(file)}"
end

.get_sha256sum(file) ⇒ Object



11
12
13
# File 'lib/specinfra/command/darwin/base/file.rb', line 11

def get_sha256sum(file)
  "ruby -e \"require 'digest'; puts Digest::SHA256.hexdigest File.read '#{escape(file)}'\""
end