etc: uid/gid support for copied files

Signed-off-by: Austin Seipp <aseipp@pobox.com>
This commit is contained in:
Austin Seipp 2014-02-18 02:09:01 -06:00
parent f6aba32af3
commit dc700e0925
3 changed files with 32 additions and 0 deletions

View File

@ -19,6 +19,8 @@ let
sources = map (x: x.source) etc'; sources = map (x: x.source) etc';
targets = map (x: x.target) etc'; targets = map (x: x.target) etc';
modes = map (x: x.mode) etc'; modes = map (x: x.mode) etc';
uids = map (x: x.uid) etc';
gids = map (x: x.gid) etc';
}; };
in in
@ -87,6 +89,24 @@ in
''; '';
}; };
uid = mkOption {
default = 0;
type = types.int;
description = ''
UID of created file. Only takes affect when the file is
copied (that is, the mode is not 'symlink').
'';
};
gid = mkOption {
default = 0;
type = types.int;
description = ''
GID of created file. Only takes affect when the file is
copied (that is, the mode is not 'symlink').
'';
};
}; };
config = { config = {

View File

@ -6,6 +6,8 @@ set -f
sources_=($sources) sources_=($sources)
targets_=($targets) targets_=($targets)
modes_=($modes) modes_=($modes)
uids_=($uids)
gids_=($gids)
set +f set +f
for ((i = 0; i < ${#targets_[@]}; i++)); do for ((i = 0; i < ${#targets_[@]}; i++)); do
@ -35,6 +37,8 @@ for ((i = 0; i < ${#targets_[@]}; i++)); do
if test "${modes_[$i]}" != symlink; then if test "${modes_[$i]}" != symlink; then
echo "${modes_[$i]}" > $out/etc/$target.mode echo "${modes_[$i]}" > $out/etc/$target.mode
echo "${uids_[$i]}" > $out/etc/$target.uid
echo "${gids_[$i]}" > $out/etc/$target.gid
fi fi
fi fi

View File

@ -60,7 +60,15 @@ sub link {
if ($mode eq "direct-symlink") { if ($mode eq "direct-symlink") {
atomicSymlink readlink("$static/$fn"), $target or warn; atomicSymlink readlink("$static/$fn"), $target or warn;
} else { } else {
open UID, "<$_.uid";
my $uid = <UID>; chomp $uid;
close UID;
open GID, "<$_.gid";
my $gid = <GID>; chomp $gid;
close GID;
copy "$static/$fn", "$target.tmp" or warn; copy "$static/$fn", "$target.tmp" or warn;
chown int($uid), int($gid), "$target.tmp" or warn;
chmod oct($mode), "$target.tmp" or warn; chmod oct($mode), "$target.tmp" or warn;
rename "$target.tmp", $target or warn; rename "$target.tmp", $target or warn;
} }