Config-Generator
view release on metacpan or search on metacpan
lib/Config/Generator/File.pm view on Meta::CPAN
sub _atomic_write ($$) {
my($path, $data) = @_;
my(@stat, $tmpath);
$tmpath = $path . ".tmp";
_unlink($tmpath) if -e $tmpath;
file_write($tmpath, data => $data);
@stat = stat($path);
if (@stat) {
_chmod($stat[ST_MODE] & oct(7777), $tmpath);
_chown($stat[ST_UID], $stat[ST_GID], $tmpath);
_unlink($path);
}
rename($tmpath, $path)
or dief("cannot rename(%s, %s): %s", $tmpath, $path, $!);
}
#
# file contents helper
#
lib/Config/Generator/File.pm view on Meta::CPAN
_atomic_write($path, \$contents);
_printf1("created %s\n", $what);
}
}
}
#
# fatal helpers
#
sub _chmod ($$) {
my($mode, $path) = @_;
chmod($mode, $path)
or dief("cannot chmod(%04o, %s): %s", $mode, $path, $!);
}
sub _chown ($$$) {
my($uid, $gid, $path) = @_;
chown($uid, $gid, $path)
or dief("cannot chown(%d, %d, %s): %s", $uid, $gid, $path, $!);
}
sub _symlink ($$) {
lib/Config/Generator/File.pm view on Meta::CPAN
if (($stat[ST_MODE] & oct(7777)) == $mode) {
_printf2("checked %s\n", $what);
} elsif ($> and $_Registered{$path}{type} eq "directory") {
# we should not change a directory mode if we are not root
# (we could shoot ourself in the foot with a read-only directory)
_printf2("would have changed %s (but we are not root)\n", $what);
} else {
if ($NoAction) {
_printf1("would have changed %s\n", $what);
} else {
_chmod($mode, $rpath);
_printf1("changed %s\n", $what);
}
}
}
#
# ensure file user
#
my @ensure_user_options = (
( run in 0.772 second using v1.01-cache-2.11-cpan-496ff517765 )