Index: pathauto.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.inc,v
retrieving revision 1.44
diff -u -p -r1.44 pathauto.inc
--- pathauto.inc	10 Jun 2008 21:41:53 -0000	1.44
+++ pathauto.inc	11 Jun 2008 07:58:22 -0000
@@ -67,7 +67,8 @@ define('PREG_CLASS_ALNUM',
 function _pathauto_alias_exists($alias, $src, $language = '') {
   $alias_pid = db_result(db_query_range("SELECT pid FROM {url_alias} WHERE dst = '%s' AND src <> '%s' AND language = '%s'", array($alias, $src, $language), 0, 1));
   if (db_table_exists('path_redirect')) {
-    $redirect_rid = db_result(db_query_range("SELECT rid FROM {path_redirect} WHERE path = '%s'", $alias, 0, 1));
+    // Check there's no redirect for this alias, excepting a redirect to itself
+    $redirect_rid = db_result(db_query_range("SELECT rid FROM {path_redirect} WHERE path = '%s' AND redirect <> '%s'", $alias, $src, 0, 1));
   }
   if ($alias_pid || !empty($redirect_rid)) {
     return TRUE;
@@ -391,6 +392,11 @@ function _pathauto_set_alias($src, $dst,
     path_set_alias($src, $dst, $pid, $language);
 
     if (variable_get('pathauto_update_action', 2) == 3 && function_exists('path_redirect_save')) {
+      // Delete from path_redirect table the exact same alias to the same node
+      // TODO: Make path_redirect_save() handle this check and possible deletion
+      if (db_table_exists('path_redirect')) {
+        db_query("DELETE FROM {path_redirect} WHERE path = '%s' AND redirect = '%s'", $old_alias, $src);
+      }
       if (!empty($old_alias)) {
         $save['path'] = $old_alias;
         $save['redirect'] = $src;
