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
17
18
19
|
# File 'lib/train/file/remote/windows.rb', line 17
def basename(suffix = nil, sep = '\\')
super(suffix, sep)
end
|
#content ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/train/file/remote/windows.rb', line 21
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
31
32
33
34
35
36
37
|
# File 'lib/train/file/remote/windows.rb', line 31
def exist?
return @exist if defined?(@exist)
@exist = @backend.run_command(
"(Test-Path -Path \"#{@spath}\").ToString()"
).stdout.chomp == "True"
end
|
#file_version ⇒ Object
72
73
74
75
76
|
# File 'lib/train/file/remote/windows.rb', line 72
def file_version
@file_version ||= @backend.run_command(
"[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"#{@spath}\").FileVersion"
).stdout.chomp
end
|
#link_path ⇒ Object
86
87
88
|
# File 'lib/train/file/remote/windows.rb', line 86
def link_path
nil
end
|
#mounted ⇒ Object
94
95
96
|
# File 'lib/train/file/remote/windows.rb', line 94
def mounted
nil
end
|
#owner ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/train/file/remote/windows.rb', line 39
def owner
owner = @backend.run_command(
"Get-Acl \"#{@spath}\" | select -expand Owner"
).stdout.strip
return if owner.empty?
owner
end
|
#product_version ⇒ Object
66
67
68
69
70
|
# File 'lib/train/file/remote/windows.rb', line 66
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
15
|
# 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
90
91
92
|
# File 'lib/train/file/remote/windows.rb', line 90
def shallow_link_path
nil
end
|
#size ⇒ Object
60
61
62
63
64
|
# File 'lib/train/file/remote/windows.rb', line 60
def size
if file?
@backend.run_command("((Get-Item '#{@spath}').Length)").stdout.strip.to_i
end
end
|
#type ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/train/file/remote/windows.rb', line 48
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
|