Config-Generator

 view release on metacpan or  search on metacpan

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

#

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

# ensure file group
#

my @ensure_group_options = (
    $ensure_directory_options[0],
    { type => SCALAR },
);

sub ensure_group ($$) {
    my($path, $group) = validate_pos(@_, @ensure_group_options);
    my($rpath, $what, $gid, @stat);

    $rpath = $RootDir . $path;
    log_debug("checking group %s", $rpath);
    dief("not a registered file or directory: %s", $path)
        unless $_Registered{$path}
           and $_Registered{$path}{type} =~ /^(file|directory)$/;
    dief("duplicate group: %s", $path) if $_Registered{$path}{group};
    $_Registered{$path}{group} = $group;
    $what = sprintf("the group of %s: %s", $rpath, $_Registered{$path}{group});
    if ($>) {
        # we do not change the group if we are not root
        # (and we stop immediately since the group may not even exist)
        _printf2("would have checked %s (but we are not root)\n", $what);
        return;
    }
    $gid = getgrnam($group);
    dief("unknown group: %s", $group) unless defined($gid);
    @stat = stat($rpath);
    unless (@stat) {
        dief("cannot stat(%s): %s", $rpath, $!)
            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.501 second using v1.01-cache-2.11-cpan-5735350b133 )