On 10/13/06, Corinna Vinschen <[EMAIL PROTECTED]> wrote:
Hi,

I got a report on the Cygwin mailing list that the following message
appears when trying to open /etc/hosts in vim:

  E303: Unable to open swap file for "/etc/hosts", recovery impossible

What happens is this:

/etc/hosts is by default a symbolic link which points to the hosts file
in the Windows system directory.  The symbolic link is created as a link
to the DOS path, for instance:

  $ ls -l /etc/hosts
  lrwxrwxrwx 1 corinna None 37 Oct 13 18:32 /etc/hosts -> 
c:\WINDOWS\system32\drivers\etc\hosts

I bet you can solve the problem by relinking /etc/hosts to
/cygdrive/c/windows/system32/drivers/etc/hosts.

This is how it *should* be linked.

It surprises me very much that your cygwin recognizes backslashes in
pathnames. I was under impression that cygwin does not recognize
backslashes in pathnames .. forward slashes as path separators.
I mean, I tried 'ls c:\windows' in cygwin and it does not work ......
strange .... is it issue of version of cygwin ? I saw even
weirder  differences in cygwin behaviour ... fat32 vs ntfs differences...


Yakov


By stracing vim I found that vim was trying to create a swap file
called "/tmp/c:\WINDOWS\system32\drivers\etc\hosts".

Cygwin is mostly treated as Unix target in vim, which is basically
correct.  However, since Cygwin allows POSIX paths as well as DOS paths,
there are both types of absolute paths.

Below is a patch which works for me, though I'm not sure if it's
complete enough to catch all cases.  There's code for OS2 in os_unix.c
which I reused, plus a new definition in mch_isFullName for the absolute
path on Cygwin.

I'd be grateful if the below or a more feasible patch which solves the
above problem, could be applied to vim.


Thanks in advance,
Corinna


--- os_unix.c.orig      2006-10-13 18:40:34.898586400 +0200
+++ os_unix.c   2006-10-13 19:01:44.398373000 +0200
@@ -2213,7 +2213,7 @@ mch_FullName(fname, buf, len, force)
     int                force;          /* also expand when already absolute 
path */
 {
     int                l;
-#ifdef OS2
+#if defined (OS2) || defined (__CYGWIN__)
     int                only_drive;     /* file name is only a drive letter */
 #endif
 #ifdef HAVE_FCHDIR
@@ -2236,7 +2236,7 @@ mch_FullName(fname, buf, len, force)
         * and then do the getwd() (and get back to where we were).
         * This will get the correct path name with "../" things.
         */
-#ifdef OS2
+#if defined (OS2) || defined (__CYGWIN__)
        only_drive = 0;
        if (((p = vim_strrchr(fname, '/')) != NULL)
                || ((p = vim_strrchr(fname, '\\')) != NULL)
@@ -2369,7 +2369,15 @@ mch_isFullName(fname)
            (strchr((char *)fname,'[') && strchr((char *)fname,']'))||
            (strchr((char *)fname,'<') && strchr((char *)fname,'>'))   );
 # else
+#  ifdef __CYGWIN__
+    /* POSIX and DOS paths are possible. */
+    return (*fname == '/' || *fname == '~'
+           || (isalpha (fname[0]) && fname[1] == ':'
+               && (fname[2] == '/' || fname[2] == '\\'))
+           || (fname[0] == '\\' && fname[1] == '\\'));
+#  else
     return (*fname == '/' || *fname == '~');
+#  endif
 # endif
 #endif
 }


--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat

Reply via email to