Index: modules/path/path.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/path/path.admin.inc,v
retrieving revision 1.34
diff -u -p -r1.34 path.admin.inc
--- modules/path/path.admin.inc	15 Oct 2009 17:53:34 -0000	1.34
+++ modules/path/path.admin.inc	15 Oct 2009 21:07:10 -0000
@@ -8,6 +8,7 @@
 
 /**
  * Return a listing of all defined URL aliases.
+ *
  * When filter key passed, perform a standard search on the given key,
  * and return the list of matching URL aliases.
  */
@@ -156,11 +157,11 @@ function path_admin_form_validate($form,
   $language = isset($form_state['values']['language']) ? $form_state['values']['language'] : '';
 
   $has_alias = db_query("SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND language = :language", array(
-    ':pid'      => $pid,
-    ':alias'    => $alias,
-    ':language' => $language,
-  ))
-  ->fetchField();
+      ':pid' => $pid,
+      ':alias' => $alias,
+      ':language' => $language,
+    ))
+    ->fetchField();
 
   if ($has_alias) {
     form_set_error('alias', t('The alias %alias is already in use in this language.', array('%alias' => $alias)));
@@ -175,17 +176,13 @@ function path_admin_form_validate($form,
  * Save a URL alias to the database.
  */
 function path_admin_form_submit($form, &$form_state) {
-  $path = array();
-  foreach (array('source', 'alias', 'pid', 'language') as $key) {
-    if (isset($form_state['values'][$key])) {
-      $path[$key] = $form_state['values'][$key];
-    }
-  }
-  path_save($path);
+  // Remove unnecessary values.
+  form_state_values_clean($form_state);
+
+  path_save($form_state['values']);
 
   drupal_set_message(t('The alias has been saved.'));
   $form_state['redirect'] = 'admin/config/search/path';
-  return;
 }
 
 /**
@@ -211,7 +208,6 @@ function path_admin_delete_confirm_submi
   if ($form_state['values']['confirm']) {
     path_delete($form_state['path']['pid']);
     $form_state['redirect'] = 'admin/config/search/path';
-    return;
   }
 }
 
Index: modules/path/path.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/path/path.module,v
retrieving revision 1.171
diff -u -p -r1.171 path.module
--- modules/path/path.module	15 Oct 2009 17:53:34 -0000	1.171
+++ modules/path/path.module	15 Oct 2009 21:05:20 -0000
@@ -22,8 +22,10 @@ function path_help($path, $arg) {
       $output .= '<p>' . t('This module also provides user-defined mass URL aliasing capabilities, which is useful if you wish to uniformly use URLs different from the default. For example, you may want to have your URLs presented in a different language. Access to the Drupal source code on the web server is required to set up mass URL aliasing.') . ' </p>';
       $output .= '<p>' . t('For more information, see the online handbook entry for <a href="@path">Path module</a>.', array('@path' => 'http://drupal.org/handbook/modules/path/')) . '</p>';
       return $output;
+
     case 'admin/config/search/path':
       return '<p>' . t("An alias defines a different name for an existing URL path - for example, the alias 'about' for the URL path 'node/1'. A URL path can have multiple aliases.") . '</p>';
+
     case 'admin/config/search/path/add':
       return '<p>' . t('Enter the path you wish to create the alias for, followed by the name of the new alias.') . '</p>';
   }
@@ -83,10 +85,10 @@ function path_load($criteria) {
   if (is_numeric($criteria)) {
     $criteria = array('pid' => $criteria);
   }
-  else if (is_string($criteria)) {
+  elseif (is_string($criteria)) {
     $criteria = array('source' => $criteria);
   }
-  else if (!is_array($criteria)) {
+  elseif (!is_array($criteria)) {
     return FALSE;
   }
   $select = db_select('url_alias');
@@ -111,29 +113,21 @@ function path_load($criteria) {
  */
 function path_save($path) {
   $path += array('language' => '', 'pid' => 0);
-  $pid = empty($path['pid']) ? 0 : $path['pid'];
-  $new = (bool) $pid;
-  unset($path['pid']);
-  // Make sure that this combination of source, alias, language wasn't save before.
-  $loaded_path = path_load($path);
-  if ($loaded_path) {
-    return $loaded_path;
-  }
-  if ($pid) {
-    db_update('url_alias')
-      ->fields($path)
-      ->condition('pid', $pid)
-      ->execute();
-  }
-  else {
-   $pid = db_insert('url_alias')
-     ->fields($path)
-     ->execute();
+
+  // Insert or update the alias.
+  $status = drupal_write_record('url_alias', $path, 'pid');
+
+  // Verify that a record as written.
+  if (isset($status) && $status) {
+    if ($status === SAVED_NEW) {
+      module_invoke_all('path_insert', $path);
+    }
+    else {
+      module_invoke_all('path_update', $path);
+    }
+    drupal_clear_path_cache();
   }
-  $path['pid'] = $pid;
-  module_invoke_all('path_' . ($new ? 'insert' : 'update'), $path);
 
-  drupal_clear_path_cache();
   return $path;
 }
 
@@ -205,7 +199,6 @@ function path_node_insert($node) {
     if (!is_array($node->path)) {
       $node->path = array('alias' => $node->path);
     }
-    
     $node->path += array(
       'source' => 'node/' . $node->nid,
       'language' => isset($node->language) ? $node->language : '',
