Class: Train::File::Remote::Windows

Inherits:
Train::File::Remote show all
Defined in:
lib/train/file/remote/windows.rb

Constant Summary

Constants inherited from Train::File

DATA_FIELDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Train::File::Remote

#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

#pathObject (readonly)

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

#contentObject



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? # or size.nil? or size > 0
  @content
end

#exist?Boolean

Returns:

  • (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_versionObject



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


76
77
78
# File 'lib/train/file/remote/windows.rb', line 76

def link_path
  nil
end

#mountedObject



84
85
86
# File 'lib/train/file/remote/windows.rb', line 84

def mounted
  nil
end

#ownerObject



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_versionObject



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?
  # we do not filter :, backslash and forward slash, since they are part of the path
  @spath = path.gsub(/[<>"|?*]/, '')
end


80
81
82
# File 'lib/train/file/remote/windows.rb', line 80

def shallow_link_path
  nil
end

#sizeObject



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

#typeObject



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