From f6ffcfd73fc0d0dd731c321efab9a408a176c801 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 29 Sep 2012 14:58:17 +0200 Subject: Better checks for existing entries. --- lib/Fripost/Schema/Local.pm | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'lib/Fripost/Schema/Local.pm') diff --git a/lib/Fripost/Schema/Local.pm b/lib/Fripost/Schema/Local.pm index f497a4e..49c3d68 100644 --- a/lib/Fripost/Schema/Local.pm +++ b/lib/Fripost/Schema/Local.pm @@ -115,11 +115,29 @@ sub exists { # The trick is somewhat dirty, but it's safe enough since postfix # delivers to mailboxes, aliases, and lists with different # priorities (and lists have the lowest). -# $l =~ s/(.*)-(admin|bounces|confirm|join|leave|loop|owner|request|subscribe|unsubscribe|bounce|sendkey)$/$1/; - # ^ TODO + my @cmds = qw/admin bounces confirm join leave owner request subscribe unsubscribe bounce sendkey/; + my @tests = ( 'fvu='.$l, 'fva='.$l, 'fvl='.$l ); + + foreach (@cmds) { + # If the entry is of the form 'foo-command', we need to ensure + # that no list 'foo' exists, otherwise the new entry would + # override foo's command. + if ($l =~ s/-$_$//) { + push @tests, 'fvl='.$l; + last; + } + } + if (defined $options{t} and $options{t} eq 'list') { + # If that's a list that is to be created, we need to ensure that + # none of its commands exists. + foreach (@cmds) { + my $l2 = $l.'-'.$_; + push @tests, 'fvu='.$l2, 'fva='.$l2; + } + } - foreach my $t (qw/fvu fva fvl/) { - my $mesg = $self->ldap->search( base => "$t=$l,fvd=$d,".$self->suffix, + foreach (@tests) { + my $mesg = $self->ldap->search( base => "$_,fvd=$d,".$self->suffix, scope => 'base', deref => 'never', filter => 'objectClass=*' @@ -129,6 +147,7 @@ sub exists { die $options{'-die'}."\n" if defined $options{'-die'}; die $mesg->error."\n"; } + } return 0; } -- cgit v1.2.3