On Wed, Aug 20, 2008 at 09:41:36AM -0700, Ian Kelling wrote:
> I submitted a patch for this issue to Bram a while ago. I should have
> posted it here too. Here are the differences in mine:
> I found the issue was also already in todo.txt so I included a patch.

I'm not sure if Gautam's issue is the same as this so I'd only remove
the issue that Matt brought up.

> I changed the scope of resolve_symlink slightly different. This seems
> like a trivial difference.

Yeah, that's cleaner.

> I originally thought the same as your patch but I think the
> preprocessor use on the result of resolve_symlink gets excessive since
> we are using it multiple times now. I looked thoroughly and think
> avoiding it is rather simple.
> Take a look and tell me if you agree, etc. :)

The one issue I see with your current patch is that it always modifies
the fname variable passed into recover_names instead of only modifying
it when it is requested (i.e., list=FALSE and nr > 0).  That may not
actually be a problem in practice, but it's an unnecessary change to the
behavior of recover_names.

Simplifying makeswapname makes sense though since we're only working
with a copy of the string and not directly modifying it.

Attached patch is my original patch plus moving the resolve_symlink
declaration to the start of the file (instead of moving the definition)
and your simplification to makeswapname.

-- 
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[EMAIL PROTECTED]>
diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt
index 81492c0..080356a 100644
--- a/runtime/doc/todo.txt
+++ b/runtime/doc/todo.txt
@@ -307,10 +307,6 @@ pointer in long and seek offset in 64 bit var.
 
 Win32: patch for fullscreen mode. (Liushaolin, 2008 April 17)
 
-When file b is a link to file a and editing b twice you get the correct
-warning for existing swap file, but when trying to recover it doesn't find the
-swapfile. (Matt Wozniski, 2008 Aug 5)
-
 Pressing the 'pastetoggle' key doesn't update the statusline. (Jan Christoph
 Ebersbach, 2008 Feb 1)
 
diff --git a/src/memline.c b/src/memline.c
index f5a68b1..b4a8b1d 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -245,6 +245,9 @@ static char_u *make_percent_swname __ARGS((char_u *dir, char_u *name));
 #ifdef FEAT_BYTEOFF
 static void ml_updatechunk __ARGS((buf_T *buf, long line, long len, int updtype));
 #endif
+#ifdef HAVE_READLINK
+static int resolve_symlink __ARGS((char_u *fname, char_u *buf));
+#endif
 
 /*
  * Open a new memline for "buf".
@@ -1390,6 +1393,17 @@ recover_names(fname, list, nr)
     int		i;
     char_u	*dirp;
     char_u	*dir_name;
+#ifdef HAVE_READLINK
+    char_u	fname_buf[MAXPATHL];
+    char_u	*fname_res;
+
+    /* Expand symlink in the file name, so that we put the swap file with the
+     * actual file instead of with the symlink. */
+    if (resolve_symlink(*fname, fname_buf) == OK)
+	fname_res = fname_buf;
+    else
+	fname_res = *fname;
+#endif
 
     if (list)
     {
@@ -1442,7 +1456,13 @@ recover_names(fname, list, nr)
 #endif
 	    }
 	    else
-		num_names = recov_file_names(names, *fname, TRUE);
+		num_names = recov_file_names(names,
+#ifdef HAVE_READLINK
+					     fname_res,
+#else
+					     *fname,
+#endif
+					     TRUE);
 	}
 	else			    /* check directory dir_name */
 	{
@@ -1479,12 +1499,24 @@ recover_names(fname, list, nr)
 		if (after_pathsep(dir_name, p) && p[-1] == p[-2])
 		{
 		    /* Ends with '//', Use Full path for swap name */
-		    tail = make_percent_swname(dir_name, *fname);
+		    tail = make_percent_swname(dir_name,
+#ifdef HAVE_READLINK
+					       fname_res
+#else
+					       *fname
+#endif
+					       );
 		}
 		else
 #endif
 		{
-		    tail = gettail(*fname);
+		    tail = gettail(
+#ifdef HAVE_READLINK
+				   fname_res
+#else
+				   *fname
+#endif
+				   );
 		    tail = concat_fnames(dir_name, tail, TRUE);
 		}
 		if (tail == NULL)
@@ -1524,11 +1556,18 @@ recover_names(fname, list, nr)
 	    struct stat	    st;
 	    char_u	    *swapname;
 
+	    swapname = modname(
+#ifdef HAVE_READLINK
+			       fname_res,
+#else
+			       *fname,
+#endif
 #if defined(VMS) || defined(RISCOS)
-	    swapname = modname(*fname, (char_u *)"_swp", FALSE);
+			       (char_u *)"_swp", FALSE
 #else
-	    swapname = modname(*fname, (char_u *)".swp", TRUE);
+			       (char_u *)".swp", TRUE
 #endif
+			      );
 	    if (swapname != NULL)
 	    {
 		if (mch_stat((char *)swapname, &st) != -1)	    /* It exists! */
@@ -3483,8 +3522,6 @@ ml_lineadd(buf, count)
 }
 
 #ifdef HAVE_READLINK
-static int resolve_symlink __ARGS((char_u *fname, char_u *buf));
-
 /*
  * Resolve a symlink in the last component of a file name.
  * Note that f_resolve() does it for every part of the path, we don't do that
@@ -3579,7 +3616,6 @@ makeswapname(fname, ffname, buf, dir_name)
     char_u	*r, *s;
 #ifdef HAVE_READLINK
     char_u	fname_buf[MAXPATHL];
-    char_u	*fname_res;
 #endif
 
 #if defined(UNIX) || defined(WIN3264)  /* Need _very_ long file names */
@@ -3600,9 +3636,7 @@ makeswapname(fname, ffname, buf, dir_name)
     /* Expand symlink in the file name, so that we put the swap file with the
      * actual file instead of with the symlink. */
     if (resolve_symlink(fname, fname_buf) == OK)
-	fname_res = fname_buf;
-    else
-	fname_res = fname;
+	fname = fname_buf;
 #endif
 
     r = buf_modname(
@@ -3615,11 +3649,7 @@ makeswapname(fname, ffname, buf, dir_name)
 	    /* Avoid problems if fname has special chars, eg <Wimp$Scrap> */
 	    ffname,
 #else
-# ifdef HAVE_READLINK
-	    fname_res,
-# else
 	    fname,
-# endif
 #endif
 	    (char_u *)
 #if defined(VMS) || defined(RISCOS)

Attachment: signature.asc
Description: Digital signature

Raspunde prin e-mail lui