Changeset 724 for trunk


Ignore:
Timestamp:
05/20/15 14:11:36 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Fixes in deleteCascade() for edge cases along with some hefty docucomments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r723 r724  
    214214  my $dbh = shift;
    215215  my $id = shift;
     216  my $createfb = shift;  # may be null at this point
    216217
    217218  my $binfo = getBlockData($dbh, $id);
     219
     220  # Decide if we're going to add a free block.
     221
     222  # Caller is normal block delete -> add freeblock under $binfo->{parent_id} -> pass nothing
     223  # Caller is delete for merge to leaf -> do not add freeblock -> pass 0
     224  # Caller is normal master delete -> do not add freeblock -> pass nothing
     225  # Caller is merge master -> add freeblock under alternate parent -> pass parent ID
     226  if ($binfo->{type} ne 'mm') {
     227    # Deleting a non-master block
     228    if (!defined($createfb)) {
     229      # No createfb flag passed;  assuming normal block delete.  Add the freeblock
     230      # under the parent of the block we're deleting.
     231      $createfb = $binfo->{parent_id};
     232    #} else {
     233      # Don't need to actually do anything here.  The caller has given us an ID,
     234      # which is either 0 (causing no free block) or (theoretically) a valid block
     235      # ID to add the free block under.
     236    }
     237  #} else {
     238    # Deleting a master block
     239    # Don't need to actually do anything here.  If the caller passed a parent ID,
     240    # that parent will get the new free block.   if the caller didn't pass anything,
     241    # no free block will be added.
     242  }
    218243
    219244##fixme:  special-case master blocks up here and quickly delete based on master_id,
     
    279304  $dbh->do("DELETE FROM poolips WHERE parent_id IN ($b)", undef, (@dellist) );
    280305
    281   # Insert a new free block in the target's parent, unless we just deleted a whole master block.
    282   if ($binfo->{type} ne 'mm') {
    283     my $pinfo = getBlockData($dbh, $binfo->{parent_id});
     306  # Insert a new free block if needed
     307  if ($createfb) {
     308    my $pinfo = getBlockData($dbh, $createfb);
    284309    my $pt = (split //, $pinfo->{type})[1];
    285310    $dbh->do("INSERT INTO freeblocks (cidr,city,routed,parent_id,vrf,master_id) VALUES (?,?,?,?,?,?)", undef,
    286         $binfo->{block}, $pinfo->{city}, $pt, $binfo->{parent_id}, $pinfo->{vrf}, $binfo->{master_id});
     311        $binfo->{block}, $pinfo->{city}, $pt, $createfb, $pinfo->{vrf}, $binfo->{master_id});
    287312  }
    288313
    289314##todo: and hey!  bonus!  we can return @dellist, or something (%cidrlist{@dellist})
     315
    290316} # end _deleteCascade()
    291317
Note: See TracChangeset for help on using the changeset viewer.