Source

Quad-Pres / installer / perl5 / Shlomif / Quad / Pres / FS.pm

Full commit
package Shlomif::Quad::Pres::FS;

use strict;

use Shlomif::Gamla::Object;

use vars qw(@ISA);

@ISA=qw(Shlomif::Gamla::Object);

use Config::IniFiles;

sub initialize
{
    my $self = shift;

    my $group;

    $self->initialize_analyze_args(
        {
            '[Gg]roup' => sub { my $new_group = shift; $group = $new_group; },
        },
        @_
    );

    $self->set_group($group);

    # Set the umask to ensure that other users which are a member of $group
    # can write to the files and directories generated by the program.
    umask(0002);

    return 0;
}

sub set_group
{
    my $self = shift;

    my $group = shift;

    $self->{'group'} = $group;

    my $gid;

    if (defined($group))
    {
        if ($group =~ /^\d+$/)
        {
            $gid = $group;
        }
        else
        {
            my @group_info = getgrnam($group);
            if (@group_info)
            {
                $gid = $group_info[2];
            }
        }
    }

    $self->{'gid'} = $gid;

    return 0;    
}

sub my_chown
{
    my $self = shift;
    
    my $path = shift;

    if (!exists($self->{gid}))
    {
        return;
    }
    
    chown(-1,$self->{'gid'}, $path);
}


sub make_dest_dir
{
    my $self = shift;

    my $dest_dir = shift;

    # Check if the destination directory exists and if not -
    # create it.
    if (! -e $dest_dir)
    {
        mkdir($dest_dir);
        # Make it belong to the common group 
        $self->my_chown($dest_dir);
        # Make it a SGID directory
        # This means that subsequent files will belong to its group.
        # And that subsequent directories inside will also be SGID.
        chmod(02775, $dest_dir);
    }
}


1;