Class: Train::File::Remote::Windows
Constant Summary
Constants inherited
from Train::File
DATA_FIELDS
Instance Attribute Summary collapse
Instance Method Summary
collapse
#stat
Methods inherited from Train::File
#block_device?, #character_device?, #directory?, #file?, #initialize, #md5sum, #mounted?, #owned_by?, #pipe?, #sha256sum, #socket?, #source, #source_path, #symlink?, #to_json, #version?
Constructor Details
This class inherits a constructor from Train::File
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
7
8
9
|
# File 'lib/train/file/remote/windows.rb', line 7
def path
@path
end
|
Instance Method Details
#basename(suffix = nil, sep = '\\') ⇒ Object
16
17
18
|
# File 'lib/train/file/remote/windows.rb', line 16
def basename(suffix = nil, sep = '\\')
super(suffix, sep)
end
|
#content ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/train/file/remote/windows.rb', line 20
def content
return @content if defined?(@content)
@content = @backend.run_command("Get-Content(\"#{@spath}\") | Out-String").stdout
return @content unless @content.empty?
@content = nil if directory? @content
end
|
#exist? ⇒ Boolean
28
29
30
31
32
|
# File 'lib/train/file/remote/windows.rb', line 28
def exist?
return @exist if defined?(@exist)
@exist = @backend.run_command(
"(Test-Path -Path \"#{@spath}\").ToString()").stdout.chomp == 'True'
end
|
#file_version ⇒ Object
63
64
65
66
|
# File 'lib/train/file/remote/windows.rb', line 63
def file_version
@file_version ||= @backend.run_command(
"[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"#{@spath}\").FileVersion").stdout.chomp
end
|
#link_path ⇒ Object
76
77
78
|
# File 'lib/train/file/remote/windows.rb', line 76
def link_path
nil
end
|
#mounted ⇒ Object
84
85
86
|
# File 'lib/train/file/remote/windows.rb', line 84
def mounted
nil
end
|
#owner ⇒ Object
34
35
36
37
38
39
|
# File 'lib/train/file/remote/windows.rb', line 34
def owner
owner = @backend.run_command(
"Get-Acl \"#{@spath}\" | select -expand Owner").stdout.strip
return if owner.empty?
owner
end
|
#product_version ⇒ Object
58
59
60
61
|
# File 'lib/train/file/remote/windows.rb', line 58
def product_version
@product_version ||= @backend.run_command(
"[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"#{@spath}\").ProductVersion").stdout.chomp
end
|
#sanitize_filename(path) ⇒ Object
Ensures we do not use invalid characters for file names
10
11
12
13
14
|
# File 'lib/train/file/remote/windows.rb', line 10
def sanitize_filename(path)
return if path.nil?
@spath = path.gsub(/[<>"|?*]/, '')
end
|
#shallow_link_path ⇒ Object
80
81
82
|
# File 'lib/train/file/remote/windows.rb', line 80
def shallow_link_path
nil
end
|
#size ⇒ Object
52
53
54
55
56
|
# File 'lib/train/file/remote/windows.rb', line 52
def size
if file?
@backend.run_command("((Get-Item '#{@spath}').Length)").stdout.strip.to_i
end
end
|
#type ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/train/file/remote/windows.rb', line 41
def type
if attributes.include?('Archive') && !attributes.include?('Directory')
return :file
elsif attributes.include?('ReparsePoint')
return :symlink
elsif attributes.include?('Directory')
return :directory
end
:unknown
end
|