Index: trunk/tools/delete_convolved_diff.pl
===================================================================
--- trunk/tools/delete_convolved_diff.pl	(revision 27106)
+++ trunk/tools/delete_convolved_diff.pl	(revision 27241)
@@ -46,5 +46,31 @@
 my @files;                      # Files to clean up
 {
-    my $sql = "SELECT path_base FROM diffSkyfile JOIN diffRun USING(diff_id) JOIN magicRun USING(diff_id) WHERE diffRun.state IN ('full', 'drop') AND magicRun.state IN ('full', 'drop', 'censored') AND diffSkyfile.hostname = '$hostname'";
+
+    my $sql = <<SQL_DONE;
+SELECT path_base
+FROM diffRun
+JOIN diffSkyfile USING(diff_id)
+JOIN magicRun USING(diff_id)
+WHERE diffRun.state IN ('full', 'drop')
+    AND magicRun.state IN ('full', 'drop', 'censored')
+    AND diffRun.bothways = 0
+    AND diffSkyfile.hostname = '$hostname'
+UNION
+SELECT path_base
+FROM diffRun
+JOIN diffSkyfile USING(diff_id)
+JOIN magicRun AS magicPositive
+    ON magicPositive.diff_id = diffRun.diff_id
+    AND magicPositive.inverse = 0
+JOIN magicRun AS magicNegative
+    ON magicNegative.diff_id = diffRun.diff_id
+    AND magicNegative.inverse = 1
+WHERE diffRun.state IN ('full', 'drop')
+    AND magicPositive.state IN ('full', 'drop', 'censored')
+    AND magicNegative.state IN ('full', 'drop', 'censored')
+    AND diffRun.bothways = 1
+    AND diffSkyfile.hostname = '$hostname'
+SQL_DONE
+
     my $results = $db->selectall_arrayref( $sql ) or die "Unable to execute SQL: $DBI::errstr";
     foreach my $result ( @$results ) {
