From 9f74cbe08823afc6a6efcb1f2c2dad52a5d92e88 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 27 May 2005 05:25:53 +0000 Subject: add addVarsInSh() and addVarsInShMode() --- MDK/Common/System.pm | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/MDK/Common/System.pm b/MDK/Common/System.pm index 0f3dee8..c0dfbb2 100644 --- a/MDK/Common/System.pm +++ b/MDK/Common/System.pm @@ -110,6 +110,18 @@ restrict the fields that will be printed to LIST like setVarsInSh with INT being the chmod value for the config file +=item addVarsInSh(FILENAME, HASH REF) + +like setVarsInSh but keeping the entries in the file + +=item addVarsInSh(FILENAME, HASH REF, LIST) + +like setVarsInSh but keeping the entries in the file + +=item addVarsInShMode(FILENAME, INT, HASH REF, LIST) + +like addVarsInShMode but keeping the entries in the file + =item setExportedVarsInCsh(FILENAME, HASH REF, LIST) same as C for csh format @@ -179,7 +191,7 @@ use MDK::Common::File; use Exporter; our @ISA = qw(Exporter); -our @EXPORT_OK = qw(%compat_arch $printable_chars $sizeof_int $bitof_int arch distrib typeFromMagic list_passwd list_home list_skels list_users syscall_ psizeof availableMemory availableRamMB gettimeofday unix2dos whereis_binary getVarsFromSh setVarsInSh setVarsInShMode setExportedVarsInSh setExportedVarsInCsh template2file template2userfile read_gnomekderc update_gnomekderc fuzzy_pidofs); #); +our @EXPORT_OK = qw(%compat_arch $printable_chars $sizeof_int $bitof_int arch distrib typeFromMagic list_passwd list_home list_skels list_users syscall_ psizeof availableMemory availableRamMB gettimeofday unix2dos whereis_binary getVarsFromSh setVarsInSh setVarsInShMode addVarsInSh addVarsInShMode setExportedVarsInSh setExportedVarsInCsh template2file template2userfile read_gnomekderc update_gnomekderc fuzzy_pidofs); #); our %EXPORT_TAGS = (all => [ @EXPORT_OK ]); @@ -331,6 +343,22 @@ sub getVarsFromSh { %l; } +sub addVarsInSh { + my ($file, $l, @fields) = @_; + addVarsInShMode($file, 0777 ^ umask(), $l, @fields); +} + +sub addVarsInShMode { + my ($file, $mod, $l, @fields) = @_; + my %l = map { $_ => $l->{$_} } @fields; + my %l2 = getVarsFromSh($file); + + # below is add2hash_(\%l, \%l2); + exists $l{$_} or $l{$_} = $l2{$_} foreach keys %l2; + + setVarsInShMode($file, $mod, \%l); +} + sub setVarsInSh { my ($file, $l, @fields) = @_; setVarsInShMode($file, 0777 ^ umask(), $l, @fields); -- cgit v1.2.1