[vhffs-dev] [2293] groups: propagate deletion error state from objects to the parent group

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 2293
Author:   gradator
Date:     2016-02-06 22:43:12 +0100 (Sat, 06 Feb 2016)
Log Message:
-----------
groups: propagate deletion error state from objects to the parent group

Forbid the parent group to create an endless loop by setting an object
in the waiting for deletion while the object previously failed to be deleted
over and over.

Prevent an endless try to delete the group in this case by setting the
group itself in deletion error if one of its child failed to be deleted,
thus propagating the deletion error state from childs to parent group.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Group.pm

Modified: trunk/vhffs-api/src/Vhffs/Robots/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Group.pm	2016-02-06 20:33:24 UTC (rev 2292)
+++ trunk/vhffs-api/src/Vhffs/Robots/Group.pm	2016-02-06 21:43:12 UTC (rev 2293)
@@ -104,14 +104,27 @@
 
 	# Recursively delete group objects, do not delete the group until this is done
 	unless( $group->is_empty )  {
+		my $pendingdelete = 0;
 		foreach( @{$group->getall_objects} ) {
 			next if $group->get_oid == $_->get_oid;
 			next if $_->get_status == Vhffs::Constants::WAITING_FOR_DELETION;
+			next if $_->get_status == Vhffs::Constants::DELETION_ERROR;
+			$pendingdelete = 1;
 			$_->set_status( Vhffs::Constants::WAITING_FOR_DELETION );
 			$_->commit;
 		}
+		Vhffs::Robots::vhffs_log( $vhffs, 'Cannot delete group '.$group->get_groupname.' because it is not empty yet, delete status have been set to group items' ) if $pendingdelete;
 
-		Vhffs::Robots::vhffs_log( $vhffs, 'Cannot delete group '.$group->get_groupname.' because it is not empty yet, delete status have been set to group items' );
+		# We are checking objects DELETION_ERROR state in a second pass to ensure WAITING_FOR_DELETION state is set to as much objects as possible
+		foreach( @{$group->getall_objects} ) {
+			next if $group->get_oid == $_->get_oid;
+			next unless $_->get_status == Vhffs::Constants::DELETION_ERROR;
+			Vhffs::Robots::vhffs_log( $vhffs, 'Cannot delete group '.$group->get_groupname.' because one of its objects have failed to be deleted' );
+			$group->set_status( Vhffs::Constants::DELETION_ERROR );
+			$group->commit;
+			return undef;
+		}
+
 		return 1;
 	}
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/