Merge pull request #208694 from ncfavier/resolvconf-nixos-enter

authored by Naïm Favier and committed by GitHub aa3dc8b8 46950548

+18 -5
+18 -5
nixos/modules/system/etc/setup-etc.pl
··· 13 my $tmp = "$target.tmp"; 14 unlink $tmp; 15 symlink $source, $tmp or return 0; 16 - rename $tmp, $target or return 0; 17 - return 1; 18 } 19 20 ··· 87 88 sub link { 89 my $fn = substr $File::Find::name, length($etc) + 1 or next; 90 my $target = "/etc/$fn"; 91 File::Path::make_path(dirname $target); 92 $created{$fn} = 1; ··· 103 if (-e "$_.mode") { 104 my $mode = read_file("$_.mode"); chomp $mode; 105 if ($mode eq "direct-symlink") { 106 - atomicSymlink readlink("$static/$fn"), $target or warn; 107 } else { 108 my $uid = read_file("$_.uid"); chomp $uid; 109 my $gid = read_file("$_.gid"); chomp $gid; ··· 112 $gid = getgrnam $gid unless $gid =~ /^\+/; 113 chown int($uid), int($gid), "$target.tmp" or warn; 114 chmod oct($mode), "$target.tmp" or warn; 115 - rename "$target.tmp", $target or warn; 116 } 117 push @copied, $fn; 118 print CLEAN "$fn\n"; 119 } elsif (-l "$_") { 120 - atomicSymlink "$static/$fn", $target or warn; 121 } 122 } 123
··· 13 my $tmp = "$target.tmp"; 14 unlink $tmp; 15 symlink $source, $tmp or return 0; 16 + if (rename $tmp, $target) { 17 + return 1; 18 + } else { 19 + unlink $tmp; 20 + return 0; 21 + } 22 } 23 24 ··· 91 92 sub link { 93 my $fn = substr $File::Find::name, length($etc) + 1 or next; 94 + 95 + # nixos-enter sets up /etc/resolv.conf as a bind mount, so skip it. 96 + if ($fn eq "resolv.conf" and $ENV{'IN_NIXOS_ENTER'}) { 97 + return; 98 + } 99 + 100 my $target = "/etc/$fn"; 101 File::Path::make_path(dirname $target); 102 $created{$fn} = 1; ··· 113 if (-e "$_.mode") { 114 my $mode = read_file("$_.mode"); chomp $mode; 115 if ($mode eq "direct-symlink") { 116 + atomicSymlink readlink("$static/$fn"), $target or warn "could not create symlink $target"; 117 } else { 118 my $uid = read_file("$_.uid"); chomp $uid; 119 my $gid = read_file("$_.gid"); chomp $gid; ··· 122 $gid = getgrnam $gid unless $gid =~ /^\+/; 123 chown int($uid), int($gid), "$target.tmp" or warn; 124 chmod oct($mode), "$target.tmp" or warn; 125 + unless (rename "$target.tmp", $target) { 126 + warn "could not create target $target"; 127 + unlink "$target.tmp"; 128 + } 129 } 130 push @copied, $fn; 131 print CLEAN "$fn\n"; 132 } elsif (-l "$_") { 133 + atomicSymlink "$static/$fn", $target or warn "could not create symlink $target"; 134 } 135 } 136