mirror of https://github.com/jimsalterjrs/sanoid
Merge 88a09b141e into 8e1d11e0b2
This commit is contained in:
commit
9715eae1b7
35
sanoid
35
sanoid
|
|
@ -1056,6 +1056,12 @@ sub init {
|
|||
$rawtemplate =~ s/\s+$//g;
|
||||
|
||||
my $template = 'template_'.$rawtemplate;
|
||||
|
||||
# Check if template exists
|
||||
if (!exists $ini{$template}) {
|
||||
die "FATAL ERROR: Template '$rawtemplate' referenced in section [$section] does not exist in $conf_file.\n";
|
||||
}
|
||||
|
||||
foreach my $key (keys %{$ini{$template}}) {
|
||||
if ($key =~ /template|recursive/) {
|
||||
warn "ignored key '$key' from '$rawtemplate' template.\n";
|
||||
|
|
@ -1175,6 +1181,35 @@ sub init {
|
|||
}
|
||||
}
|
||||
|
||||
# Check for unused templates
|
||||
my %defined_templates;
|
||||
my %used_templates;
|
||||
|
||||
# Collect all defined templates
|
||||
foreach my $section (keys %ini) {
|
||||
if ($section =~ /^template_(.+)$/) {
|
||||
$defined_templates{$1} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
# Collect all used templates
|
||||
foreach my $section (keys %ini) {
|
||||
if ($section !~ /^template_/ && defined $ini{$section}{'use_template'}) {
|
||||
my @templates = split (' *, *', $ini{$section}{'use_template'});
|
||||
foreach my $rawtemplate (@templates) {
|
||||
$rawtemplate =~ s/\s+$//g; # strip trailing whitespace
|
||||
$used_templates{$rawtemplate} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Check for unused templates (excluding template_default)
|
||||
foreach my $template (keys %defined_templates) {
|
||||
if ($template ne 'default' && !exists $used_templates{$template}) {
|
||||
die "FATAL ERROR: Template '$template' is defined but never used in $conf_file.\n";
|
||||
}
|
||||
}
|
||||
|
||||
return %config;
|
||||
} # end sub init
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue