From ed1bc1e180025db9c6a3d434bc34a2b0341a2444 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 6 Sep 2011 12:32:07 +0000 Subject: [PATCH] * Handle the case where a symlink in /etc needs to change into a directory. This happened with /etc/polkit-1, which used to be a symlink to /etc/static/polkit-1, which was itself a symlink but now is a directory. Not handling this correctly led to /etc/static being clobbered with symlinks pointing to themselves. svn path=/nixos/trunk/; revision=29061 --- modules/system/etc/make-etc.sh | 1 + modules/system/etc/setup-etc.pl | 45 ++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/modules/system/etc/make-etc.sh b/modules/system/etc/make-etc.sh index 70cb57bc635..a5866d0a349 100644 --- a/modules/system/etc/make-etc.sh +++ b/modules/system/etc/make-etc.sh @@ -20,3 +20,4 @@ for ((i = 0; i < ${#targets_[@]}; i++)); do echo "${modes_[$i]}" > $out/etc/${targets_[$i]}.mode fi done + diff --git a/modules/system/etc/setup-etc.pl b/modules/system/etc/setup-etc.pl index c6b932cf202..7cb6d2a6a45 100644 --- a/modules/system/etc/setup-etc.pl +++ b/modules/system/etc/setup-etc.pl @@ -22,6 +22,30 @@ sub atomicSymlink { atomicSymlink $etc, $static or die; +# Remove dangling symlinks that point to /etc/static. These are +# configuration files that existed in a previous configuration but not +# in the current one. For efficiency, don't look under /etc/nixos +# (where all the NixOS sources live). +sub cleanup { + if ($File::Find::name eq "/etc/nixos") { + $File::Find::prune = 1; + return; + } + if (-l $_) { + my $target = readlink $_; + if (substr($target, 0, length $static) eq $static) { + my $x = "/etc/static/" . substr($File::Find::name, length "/etc/"); + unless (-l $x) { + print STDERR "removing obsolete symlink ‘$File::Find::name’...\n"; + unlink "$_"; + } + } + } +} + +find(\&cleanup, "/etc"); + + # For every file in the etc tree, create a corresponding symlink in # /etc to /etc/static. The indirection through /etc/static is to make # switching to a new configuration somewhat more atomic. @@ -42,24 +66,3 @@ sub link { } find(\&link, $etc); - - -# Remove dangling symlinks that point to /etc/static. These are -# configuration files that existed in a previous configuration but not -# in the current one. For efficiency, don't look under /etc/nixos -# (where all the NixOS sources live). -sub cleanup { - if ($File::Find::name eq "/etc/nixos") { - $File::Find::prune = 1; - return; - } - if (-l $_) { - my $target = readlink $_; - if (substr($target, 0, length $static) eq $static) { - my $x = "/etc/static/" . substr($File::Find::name, length "/etc/"); - unlink "$_" unless -e "$x"; - } - } -} - -find(\&cleanup, "/etc");