Class: Specinfra::Command::Windows::Base::File

Inherits:
Specinfra::Command::Windows::Base show all
Defined in:
lib/specinfra/command/windows/base/file.rb

Class Method Summary collapse

Methods inherited from Specinfra::Command::Windows::Base

create

Class Method Details

.check_contains(file, pattern) ⇒ Object



74
75
76
77
78
# File 'lib/specinfra/command/windows/base/file.rb', line 74

def check_contains(file, pattern)
  Backend::PowerShell::Command.new do
    exec %Q![Io.File]::ReadAllText("#{file}") -match '#{convert_regexp(pattern)}'!
  end
end

.check_contains_within(file, pattern, from = nil, to = nil) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/specinfra/command/windows/base/file.rb', line 80

def check_contains_within file, pattern, from=nil, to=nil
  from ||= '^'
  to ||= '$'
  Backend::PowerShell::Command.new do
    using 'crop_text.ps1'
    exec %Q!(CropText -text ([Io.File]::ReadAllText("#{file}")) -fromPattern '#{convert_regexp(from)}' -toPattern '#{convert_regexp(to)}') -match '#{pattern}'!
  end
end

.check_has_version(name, version) ⇒ Object



89
90
91
92
# File 'lib/specinfra/command/windows/base/file.rb', line 89

def check_has_version(name,version)
  cmd = "((Get-Command '#{name}').FileVersionInfo.ProductVersion -eq '#{version}') -or ((Get-Command '#{name}').FileVersionInfo.FileVersion -eq '#{version}')"
  Backend::PowerShell::Command.new { exec cmd }
end

.check_is_accessible_by_user(file, user, access) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/specinfra/command/windows/base/file.rb', line 42

def check_is_accessible_by_user(file, user, access)
  case access
  when 'r'
    check_is_readable(file, user)
  when 'w'
    check_is_writable(file, user)
  when 'x'
    check_is_executable(file, user)
  end
end

.check_is_directory(dir) ⇒ Object



10
11
12
13
14
15
# File 'lib/specinfra/command/windows/base/file.rb', line 10

def check_is_directory(dir)
  cmd = item_has_attribute dir, 'Directory'
  Backend::PowerShell::Command.new do
    exec cmd
  end
end

.check_is_executable(file, by_whom) ⇒ Object



67
68
69
70
71
72
# File 'lib/specinfra/command/windows/base/file.rb', line 67

def check_is_executable(file, by_whom)
  Backend::PowerShell::Command.new do
    using 'check_file_access_rules.ps1'
    exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'ExecuteFile')"
  end
end

.check_is_file(file) ⇒ Object



3
4
5
6
7
8
# File 'lib/specinfra/command/windows/base/file.rb', line 3

def check_is_file(file)
  cmd = item_has_attribute file, 'Archive'
  Backend::PowerShell::Command.new do
    exec cmd
  end
end

.check_is_hidden(file) ⇒ Object



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

def check_is_hidden(file)
  cmd = item_has_attribute file, 'Hidden'
  Backend::PowerShell::Command.new do
    exec cmd
  end
end

.check_is_readable(file, by_whom) ⇒ Object



53
54
55
56
57
58
# File 'lib/specinfra/command/windows/base/file.rb', line 53

def check_is_readable(file, by_whom)
  Backend::PowerShell::Command.new do
    using 'check_file_access_rules.ps1'
    exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'ReadAndExecute', 'Read', 'ListDirectory')"
  end
end

.check_is_readonly(file) ⇒ Object



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

def check_is_readonly(file)
  cmd = item_has_attribute file, 'ReadOnly'
  Backend::PowerShell::Command.new do
    exec cmd
  end
end

.check_is_system(file) ⇒ Object



31
32
33
34
35
36
# File 'lib/specinfra/command/windows/base/file.rb', line 31

def check_is_system(file)
  cmd = item_has_attribute file, 'System'
  Backend::PowerShell::Command.new do
    exec cmd
  end
end

.check_is_writable(file, by_whom) ⇒ Object



60
61
62
63
64
65
# File 'lib/specinfra/command/windows/base/file.rb', line 60

def check_is_writable(file, by_whom)
  Backend::PowerShell::Command.new do
    using 'check_file_access_rules.ps1'
    exec "CheckFileAccessRules -path '#{file}' -identity '#{get_identity by_whom}' -rules @('FullControl', 'Modify', 'Write')"
  end
end

.get_content(file) ⇒ Object



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

def get_content(file)
  %Q![Io.File]::ReadAllText("#{file}")!
end