Index: post.php
===================================================================
--- post.php	(revision 2781)
+++ post.php	(working copy)
@@ -188,11 +188,19 @@
 
 	add_meta($post_ID);
 
+	// Set the permalink regardless of post status so drafts have a valid link in the preview
 	$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
 
 	do_action('save_post', $post_ID);
 
 	if ('publish' == $post_status) {
+		// Bust the post cache to make sure permalinks work
+		global $post_cache;
+		if (isset($post_cache[$post_ID]))
+			unset($post_cache[$post_ID]);
+
+		$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
+
 		do_action('publish_post', $post_ID);
 		if ($post_pingback)
 			register_shutdown_function('pingback', $content, $post_ID);
@@ -432,6 +440,13 @@
 	do_action('edit_post', $post_ID);
 
 	if ($post_status == 'publish') {
+		// Bust the post cache to make sure permalinks work
+		global $post_cache;
+		if (isset($post_cache[$post_ID]))
+			unset($post_cache[$post_ID]);
+
+		$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
+
 		do_action('publish_post', $post_ID);
 		register_shutdown_function('do_trackbacks', $post_ID);
 		register_shutdown_function('do_enclose', $content, $post_ID );

