1509 # detect a total lack of change |
1509 # detect a total lack of change |
1510 # |
1510 # |
1511 if ( $hash_orig eq $self->chksum($self->{'ldif_fname'}) ) { |
1511 if ( $hash_orig eq $self->chksum($self->{'ldif_fname'}) ) { |
1512 print "Entry not modified.\n"; |
1512 print "Entry not modified.\n"; |
1513 unlink $self->{'ldif_fname'}; |
1513 unlink $self->{'ldif_fname'}; |
|
1514 $self->{'edit_again'} = undef; |
1514 return; |
1515 return; |
1515 } |
1516 } |
1516 |
1517 |
1517 # check changes for basic LDIF validity |
1518 # check changes for basic LDIF validity |
1518 # |
1519 # |
1552 while ( $diff->Next() ) { |
1554 while ( $diff->Next() ) { |
1553 next if $diff->Same(); |
1555 next if $diff->Same(); |
1554 my $diff_bit = $diff->Diff(); |
1556 my $diff_bit = $diff->Diff(); |
1555 my %seen_attr; |
1557 my %seen_attr; |
1556 |
1558 |
1557 # attr removals |
1559 # attr removal hunk |
1558 # |
1560 # |
1559 if ( $diff_bit == 1 ) { |
1561 if ( $diff_bit == 1 ) { |
1560 foreach ( $diff->Items(1) ) { |
1562 foreach ( $diff->Items(1) ) { |
1561 my ( $attr, $val ) = $parse->( $_ ) or next; |
1563 my ( $attr, $val ) = $parse->( $_ ) or next; |
1562 $self->debug("DELETE: $_"); |
1564 $self->debug("DELETE: $_"); |
1563 $e->delete( $attr => [ $val ] ); |
1565 $e->delete( $attr => [ $val ] ); |
1564 } |
1566 } |
1565 } |
1567 } |
1566 |
1568 |
1567 # attr insertions |
1569 # attr insertion hunk |
1568 # |
1570 # |
1569 if ( $diff_bit == 2 ) { |
1571 if ( $diff_bit == 2 ) { |
1570 foreach ( $diff->Items(2) ) { |
1572 foreach ( $diff->Items(2) ) { |
1571 my ( $attr, $val ) = $parse->( $_ ) or next; |
1573 my ( $attr, $val ) = $parse->( $_ ) or next; |
1572 $self->debug("INSERT: $_"); |
1574 $self->debug("INSERT: $_"); |
1573 $e->add( $attr => $val ); |
1575 $e->add( $attr => $val ); |
1574 } |
1576 } |
1575 } |
1577 } |
1576 |
1578 |
1577 # attr change |
1579 # attr change hunk |
1578 # |
1580 # |
1579 if ( $diff_bit == 3 ) { |
1581 if ( $diff_bit == 3 ) { |
|
1582 |
|
1583 # modification to existing line |
|
1584 # |
1580 foreach ( $diff->Items(2) ) { |
1585 foreach ( $diff->Items(2) ) { |
1581 my ( $attr, $val ) = $parse->( $_ ) or next; |
1586 my ( $attr, $val ) = $parse->( $_ ) or next; |
1582 $self->debug("MODIFY: $_"); |
1587 $self->debug("MODIFY: $_"); |
1583 |
1588 |
1584 my $cur_vals = $e->get_value( $attr, asref => 1 ) || []; |
1589 my $cur_vals = $e->get_value( $attr, asref => 1 ) || []; |
1606 } |
1611 } |
1607 |
1612 |
1608 $e->replace( $attr => \@new_vals ); |
1613 $e->replace( $attr => \@new_vals ); |
1609 } |
1614 } |
1610 } |
1615 } |
|
1616 |
|
1617 # deletion within the same hunk |
|
1618 # |
|
1619 foreach ( $diff->Items(1) ) { |
|
1620 my ( $attr, $val ) = $parse->( $_ ) or next; |
|
1621 next if $seen_attr{ $attr }; |
|
1622 $self->debug("DELETE: $_"); |
|
1623 $e->delete( $attr => [ $val ] ); |
|
1624 } |
1611 } |
1625 } |
1612 } |
1626 } |
1613 |
1627 |
1614 my $update = sub { return $e->update( $self->ldap ); }; |
1628 my $update = sub { return $e->update( $self->ldap ); }; |
1615 my $rv = $self->with_retry( $update ); |
1629 my $rv = $self->with_retry( $update ); |