shelldap
changeset 5 78b2a48e07db
parent 4 5a65bc849363
child 6 46dfe9d6f368
equal deleted inserted replaced
4:5a65bc849363 5:78b2a48e07db
   865 		my $real_sub  = 'run_' . $cmd;
   865 		my $real_sub  = 'run_' . $cmd;
   866 		*$alias_sub = \&$real_sub;
   866 		*$alias_sub = \&$real_sub;
   867 	}
   867 	}
   868 }
   868 }
   869 
   869 
       
   870 sub unwrap {
       
   871 	my $array = shift;
       
   872 
       
   873 	my $iter = 1;
       
   874 	while ($iter < $#$array) {
       
   875 		if (@$array[$iter] =~ m/^\W/) {
       
   876 			@$array[$iter - 1] =~ s/\n$//;
       
   877 			@$array[$iter] =~ s/^\W//;
       
   878 			splice(@$array, $iter - 1, 2, @$array[$iter - 1] . @$array[$iter]);
       
   879 		} else {
       
   880 			$iter++;
       
   881 		}
       
   882 	}
       
   883 }
       
   884 
   870 ###############################################################
   885 ###############################################################
   871 #
   886 #
   872 # SHELL METHODS
   887 # SHELL METHODS
   873 #
   888 #
   874 ###############################################################
   889 ###############################################################
  1231 
  1246 
  1232 	$e->changetype('modify');
  1247 	$e->changetype('modify');
  1233 
  1248 
  1234 	my $parse = sub {
  1249 	my $parse = sub {
  1235 		my $line = shift || $_;
  1250 		my $line = shift || $_;
  1236 		return unless $line =~ /^\w/; # ignore multiline
       
  1237 		return if $line	 =~ /^\#/; # ignore comments
  1251 		return if $line	 =~ /^\#/; # ignore comments
  1238 		my ( $attr, $val ) = ( $1, $2 ) if $line =~ /^(.+?): (.*)$/;
  1252 		my ( $attr, $val ) = ( $1, $2 ) if $line =~ /^(.+?): (.*)$/;
  1239 		return if index($attr, ':') != -1;  # ignore base64
  1253 		return if index($attr, ':') != -1;  # ignore base64
  1240 		return ( $attr, $val );
  1254 		return ( $attr, $val );
  1241 	};
  1255 	};
       
  1256 
       
  1257 	unwrap(\@orig_ldif);
       
  1258 	unwrap(\@new_ldif);
  1242 
  1259 
  1243 	my $diff = Algorithm::Diff->new( \@orig_ldif, \@new_ldif );
  1260 	my $diff = Algorithm::Diff->new( \@orig_ldif, \@new_ldif );
  1244 	HUNK:
  1261 	HUNK:
  1245 	while ( $diff->Next() ) {
  1262 	while ( $diff->Next() ) {
  1246 		next if $diff->Same();
  1263 		next if $diff->Same();
  1248 		my %seen_attr;
  1265 		my %seen_attr;
  1249 
  1266 
  1250 		# total deletions
  1267 		# total deletions
  1251 		if ( $diff_bit == 1 ) {
  1268 		if ( $diff_bit == 1 ) {
  1252 			foreach ( $diff->Items(1) ) {
  1269 			foreach ( $diff->Items(1) ) {
  1253 				next unless /\w+/;
       
  1254 				$self->debug("DELETE: $_");
  1270 				$self->debug("DELETE: $_");
  1255 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1271 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1256 				$e->delete( $attr => [ $val ] );
  1272 				$e->delete( $attr => [ $val ] );
  1257 			}
  1273 			}
  1258 		}
  1274 		}
  1259 
  1275 
  1260 		# new insertions
  1276 		# new insertions
  1261 		if ( $diff_bit == 2 ) {
  1277 		if ( $diff_bit == 2 ) {
  1262 			foreach ( $diff->Items(2) ) {
  1278 			foreach ( $diff->Items(2) ) {
  1263 				next unless /\w+/;
       
  1264 				$self->debug("INSERT: $_");
  1279 				$self->debug("INSERT: $_");
  1265 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1280 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1266 				$e->add( $attr => $val );
  1281 				$e->add( $attr => $val );
  1267 			}
  1282 			}
  1268 		}
  1283 		}
  1269 
  1284 
  1270 		# replacements
  1285 		# replacements
  1271 		# these are trickier with multivalue lines
       
  1272 		if ( $diff_bit == 3 ) {
  1286 		if ( $diff_bit == 3 ) {
  1273 			foreach ( $diff->Items(2) ) {
  1287 			foreach ( $diff->Items(2) ) {
  1274 				next unless /\w+/;
       
  1275 				$self->debug("MODIFY: $_");
  1288 				$self->debug("MODIFY: $_");
  1276 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1289 				my ( $attr, $val ) = $parse->( $_ ) or next;
  1277 
  1290 
  1278 				my $cur_vals = $e->get_value( $attr, asref => 1 ) || [];
  1291 				my $cur_vals = $e->get_value( $attr, asref => 1 ) || [];
  1279 				my $cur_valcount = scalar @$cur_vals;
  1292 				my $cur_valcount = scalar @$cur_vals;