From 7cf01146c8f52d3025db18d93a3ff64b9b54e971 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 1 Apr 2018 19:49:13 +0100 Subject: Revised config and settings path handling. Don't default to system dirs - we expect to run as normal user now. --- lib/MGA/DrakISO/Config.pm | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/MGA/DrakISO/Config.pm b/lib/MGA/DrakISO/Config.pm index bd99e66..98d25ea 100644 --- a/lib/MGA/DrakISO/Config.pm +++ b/lib/MGA/DrakISO/Config.pm @@ -28,7 +28,7 @@ use strict; use MDK::Common; use Pod::Usage; -use Cwd 'getcwd'; +use Cwd 'abs_path'; #- these modules can be used from config files use MGA::DrakISO::Mounts; @@ -40,18 +40,26 @@ our @EXPORT = qw(read_config check_config complete_config dump_config); sub read_config { my ($build, $config_root, $config_path, $settings_path) = @_; - if ($config_path && -e getcwd() . '/' . $config_path) { - $config_root = getcwd(); - } + $config_root = abs_path($config_root); print "Using $config_root as directory root\n"; - add2hash($build->{settings} ||= {}, { getVarsFromSh($config_root . '/' . $settings_path) }) if $settings_path; - if ($config_path) { - #- don't use do(), since it can't see lexicals in the enclosing scope - my $cfg = eval(cat_($config_root . '/' . $config_path)) or die "ERROR: unable to load $config_path: $@\n"; - put_in_hash($build, $cfg); - print "Loaded $config_path as config file\n"; + if (substr($config_path, 0, 1) ne '/') { + $config_path = $config_root . '/' . $config_path; + } + -e $config_path or die "ERROR: $config_path does not exist\n"; + + if (substr($settings_path, 0, 1) ne '/') { + $settings_path = $config_root . '/' . $settings_path; } + -e $settings_path or die "ERROR: $settings_path does not exist\n"; + + add2hash($build->{settings} ||= {}, { getVarsFromSh($settings_path) }); + + #- don't use do(), since it can't see lexicals in the enclosing scope + my $cfg = eval(cat_($config_path)) or die "ERROR: unable to load $config_path: $@\n"; + put_in_hash($build, $cfg); + print "Loaded $config_path as config file\n"; + $build->{settings}{config_root} = $config_root; } @@ -73,7 +81,7 @@ sub check_config { sub complete_config { my ($build) = @_; - $build->{settings}{workdir} ||= '/var/lib/drakiso'; + $build->{settings}{workdir} = abs_path($build->{settings}{workdir} || '.'); mkdir_p($build->get_build_dir); mkdir_p($build->get_chroot_dir); -- cgit v1.2.1