* 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
This commit is contained in:
parent
4a65eb6830
commit
ed1bc1e180
@ -20,3 +20,4 @@ for ((i = 0; i < ${#targets_[@]}; i++)); do
|
|||||||
echo "${modes_[$i]}" > $out/etc/${targets_[$i]}.mode
|
echo "${modes_[$i]}" > $out/etc/${targets_[$i]}.mode
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -22,6 +22,30 @@ sub atomicSymlink {
|
|||||||
atomicSymlink $etc, $static or die;
|
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
|
# For every file in the etc tree, create a corresponding symlink in
|
||||||
# /etc to /etc/static. The indirection through /etc/static is to make
|
# /etc to /etc/static. The indirection through /etc/static is to make
|
||||||
# switching to a new configuration somewhat more atomic.
|
# switching to a new configuration somewhat more atomic.
|
||||||
@ -42,24 +66,3 @@ sub link {
|
|||||||
}
|
}
|
||||||
|
|
||||||
find(\&link, $etc);
|
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");
|
|
||||||
|
Loading…
Reference in New Issue
Block a user