Skip to content

Commit

Permalink
Respect installation destdir when writing NM config
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jan 21, 2021
1 parent 5726546 commit 0dccce7
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/lib/y2network/network_manager/connection_config_writer.rb
Expand Up @@ -17,33 +17,51 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"
require "cfa/nm_connection"
require "pathname"

Yast.import "Installation"

module Y2Network
module NetworkManager
class ConnectionConfigWriter
include Yast::Logger

SYSTEM_CONNECTIONS_PATH = Pathname.new("/etc/NetworkManager/system-connections").freeze
FILE_EXT = ".nmconnection".freeze
# @return [String] base directory
attr_reader :basedir

# Constructor
#
# @param basedir [String]
def initialize(basedir = Yast::Installation.destdir)
@basedir = basedir
end

def write(conn, old_conn = nil)
def write(conn, old_conn = nil, routes = [])
return if conn == old_conn

path = SYSTEM_CONNECTIONS_PATH.join(conn.name).sub_ext(FILE_EXT)
path = path_for(conn)
file = CFA::NmConnection.new(path)
handler_class = find_handler_class(conn.type)
return nil if handler_class.nil?

ensure_permissions(path) unless ::File.exist?(path)

handler_class.new(file).write(conn)
handler_class.new(file).write(conn, routes)
file.save
end

private

def path_for(conn)
Yast.import "Installation"
conn_file_path = SYSTEM_CONNECTIONS_PATH.join(conn.name).sub_ext(FILE_EXT)
Pathname.new(File.join(basedir, conn_file_path))
end

def ensure_permissions(path)
::FileUtils.touch(path)
::File.chmod(0o600, path)
Expand Down

0 comments on commit 0dccce7

Please sign in to comment.