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

# 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 ($$) {
    my($target, $path) = @_;

    symlink($target, $path)
        or dief("cannot symlink(%s, %s): %s", $target, $path, $!);
}

sub _unlink ($) {

lib/Config/Generator/File.pm  view on Meta::CPAN

            unless $NoAction and $! == ENOENT;
        _printf2("would have checked %s (but it does no exist yet)\n", $what);
        return;
    }
    if ($stat[ST_UID] == $uid) {
        _printf2("checked %s\n", $what);
    } else {
        if ($NoAction) {
            _printf1("would have changed %s\n", $what);
        } else {
            _chown($uid, $stat[ST_GID], $rpath);
            _printf1("changed %s\n", $what);
        }
    }
}

#
# ensure file group
#

my @ensure_group_options = (

lib/Config/Generator/File.pm  view on Meta::CPAN

            unless $NoAction and $! == ENOENT;
        _printf2("would have checked %s (but it does no exist yet)\n", $what);
        return;
    }
    if ($stat[ST_GID] == $gid) {
        _printf2("checked %s\n", $what);
    } else {
        if ($NoAction) {
            _printf1("would have changed %s\n", $what);
        } else {
            _chown($stat[ST_UID], $gid, $rpath);
            _printf1("changed %s\n", $what);
        }
    }
}

#
# return the list of registered files (paths only)
#

sub files_manifest () {



( run in 0.891 second using v1.01-cache-2.11-cpan-71847e10f99 )