App-LXC-Container
view release on metacpan or search on metacpan
lib/App/LXC/Container/Update.pm view on Meta::CPAN
(usually C</var/lib/lxc/CONTAINER>). The path will have the same
permissions as the original one. If the update is run by root, it will also
have the same ownership as the original one.
=cut
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
sub _make_lxc_path($$)
{
my ($self, $path) = @_;
debug(4, __PACKAGE__, '::_make_lxc_path($self, "', $path, '")');
local $_ = $path . '/';
s|(?<=.)/+$||; # remove trailing / (just to be on the safe side)
my @paths = ($_);
unshift @paths, $_ while s|/+(?:[^/]+)$|| and $_;
my $root = $self->{root_fs} . '/' . $self->{name};
-d $root or mkdir $root or fatal('can_t_create__1__2', $root, $!);
foreach (@paths)
{
-e $_ or fatal('_1_does_not_exist', $path);
my $target = $root . $_;
next if -e $target;
my $stat = stat($_);
my ($mode, $uid, $gid) = ($stat->mode, $stat->uid, $stat->gid);
if (-d)
{
$mode |= 0200; # prevent blocking ourselves later on
if (-l)
{
# links can be arbitrarily deep, so we use make_path on the
# absolute path and hope for no clashes:
$target = $root . abs_path($_);
my $errors = [];
make_path($target, {chmod => $mode, error => \$errors});
$errors = join(' ', map { (values(%$_)) } @$errors);
$errors eq ''
or error('can_t_create__1__2', $target, $errors);
}
else
{
mkdir $target or fatal('can_t_create__1__2', $target, $!);
}
# There are no standard files known to me meeting condition 2 or
# 4 (but not 1 and 3):
# uncoverable condition right
# uncoverable condition right count:3
$uid == 0 or $gid == 0 or $mode & 0001 or $_ eq $path
or warning('_1_may_be_inaccessible', $_);
}
else
{
open my $f, '>', $target
or fatal('can_t_create__1__2', $target, $!);
close $f;
}
if (-W $target)
{
# ignoring errors as mounting overrules most problems anyway:
chmod $mode, $target;
chown $uid, $gid, $target;
}
}
}
#########################################################################
=head2 B<_parse_filter> - parse filter configuration file
$self->_parse_filter();
=head3 description:
This method parses the applicable global special filter meta-configuration
files and those of the chosen container(s) into the configuration object.
Note that in the case of multiple containers the filter configurations are
merged and only the last occurrence of a filter is the one used in the
created LXC configuration file.
=cut
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
sub _parse_filter($)
{
my $self = shift;
debug(2, __PACKAGE__, '::_parse_filter($self)');
my @special = ('50-default');
foreach my $container (@special, @{$self->{containers}})
{
my $fname = substr($container, 0, 1) . substr($container, -1, 1)
. '-NOT-' . $container . '.filter';
$container =~ m/^\d\d-/ and
$fname = (substr($container, 0, 2) . '-NOT-' .
substr($container, 3) . '.filter');
my $path = _ROOT_DIR_ . '/conf/' . $fname;
open my $in, '<', $path or fatal 'can_t_open__1__2', $path, $!;
local $_;
while (<$in>)
{
next if m/^\s*(?:#|$)/;
s/\s*#.*$//;
if (m{^\s*(/\S+)\s+(copy|empty|ignore|nomerge)\s*$})
{ $self->{filter}{$1} = $2; }
else
{ error 'ignoring_unknown_item_in__1__2', $path, $.; }
}
close $in;
}
}
#########################################################################
=head2 B<_parse_master> - parse master configuration file(s)
$self->_parse_master();
=head3 description:
( run in 0.360 second using v1.01-cache-2.11-cpan-71847e10f99 )