Class: Train::File::Local::Windows

Inherits:
Train::File::Local show all
Defined in:
lib/train/file/local/windows.rb

Constant Summary

Constants inherited from Train::File

DATA_FIELDS

Instance Method Summary collapse

Methods inherited from Train::File::Local

#block_device?, #character_device?, #content, #link_path, #linked_to?, #mode?, #shallow_link_path, #type

Methods inherited from Train::File

#block_device?, #character_device?, #directory?, #file?, #initialize, #md5sum, #mounted?, #owned_by?, #path, #pipe?, #sha256sum, #socket?, #source, #source_path, #symlink?, #to_json, #type, #version?

Constructor Details

This class inherits a constructor from Train::File

Instance Method Details

#file_versionObject



20
21
22
23
# File 'lib/train/file/local/windows.rb', line 20

def file_version
  @file_version ||= @backend.run_command(
    "[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"#{@spath}\").FileVersion").stdout.chomp
end

#ownerObject



25
26
27
28
29
30
# File 'lib/train/file/local/windows.rb', line 25

def owner
  owner = @backend.run_command(
    "Get-Acl \"#{@spath}\" | select -expand Owner").stdout.strip
  return if owner.empty?
  owner
end

#product_versionObject



15
16
17
18
# File 'lib/train/file/local/windows.rb', line 15

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



9
10
11
12
13
# File 'lib/train/file/local/windows.rb', line 9

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

#statObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/train/file/local/windows.rb', line 32

def stat
  return @stat if defined?(@stat)

  begin
    file_stat =
      if @follow_symlink
        ::File.stat(@path)
      else
        ::File.lstat(@path)
      end
  rescue StandardError => _err
    return @stat = {}
  end

  @stat = {
    type: type,
    mode: file_stat.mode,
    mtime: file_stat.mtime.to_i,
    size: file_stat.size,
    owner: owner,
    uid: file_stat.uid,
    group: nil,
    gid: file_stat.gid,
    selinux_label: nil,
  }

  @stat
end