Class: Installation::SshConfigFile

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
src/lib/installation/ssh_config_file.rb

Overview

Class that allows to memorize a particular SSH config file found in a partition.

Used by the SSH configuration importing functionality.

Constant Summary collapse

BACKUP_SUFFIX =
".yast.orig".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ SshConfigFile

Returns a new instance of SshConfigFile.



40
41
42
# File 'src/lib/installation/ssh_config_file.rb', line 40

def initialize(name)
  @name = name
end

Instance Attribute Details

#atimeTime

Returns access time of the original file.

Returns:

  • (Time)

    access time of the original file



34
35
36
# File 'src/lib/installation/ssh_config_file.rb', line 34

def atime
  @atime
end

#contentString

Returns content of the file.

Returns:

  • (String)

    content of the file



36
37
38
# File 'src/lib/installation/ssh_config_file.rb', line 36

def content
  @content
end

#nameString

Returns file name.

Returns:

  • (String)

    file name



32
33
34
# File 'src/lib/installation/ssh_config_file.rb', line 32

def name
  @name
end

#permissionsFixmum

Returns mode of the original file. @see File.chmod.

Returns:

  • (Fixmum)

    mode of the original file. @see File.chmod



38
39
40
# File 'src/lib/installation/ssh_config_file.rb', line 38

def permissions
  @permissions
end

Instance Method Details

#backup(filename) ⇒ Object (protected)



65
66
67
# File 'src/lib/installation/ssh_config_file.rb', line 65

def backup(filename)
  ::FileUtils.mv(filename, filename + BACKUP_SUFFIX) if File.exist?(filename)
end

#read(path) ⇒ Object



44
45
46
47
48
# File 'src/lib/installation/ssh_config_file.rb', line 44

def read(path)
  self.content = File.read(path)
  self.atime = File.atime(path)
  self.permissions = File.stat(path).mode
end

#to_sObject

Override to_s method for logging.



59
60
61
# File 'src/lib/installation/ssh_config_file.rb', line 59

def to_s
  name.to_s
end

#write(dir) ⇒ Object



50
51
52
53
54
55
56
# File 'src/lib/installation/ssh_config_file.rb', line 50

def write(dir)
  log.info "Write SSH config file #{dir} to #{name}"
  path = File.join(dir, name)
  backup(path)
  File.write(path, content)
  File.chmod(permissions, path)
end