This is the mail archive of the insight@sourceware.org mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH/RFC]: Keep cygwin's and native Windows cwd in sync


Hi,

my latest changes to Cygwin introduce a divergence between the current
working directory of Cygwin applications in contrast to the native
current working directory.  The idea is that Cygwin applications have
the native path set to some "always safe" value instead of the real cwd,
thus allowing to manipulate the current working directory in a POSIXy
way which native Windows doesn't allow.  For instance, under Windows an
application can't rmdir a directory which is the cwd of any other
application, which is now possible in Cygwin as long as only Cygwin
processes are involved.

This introduces a problem to Cygwin tcl.  Cygwin tcl is using a colorful
mix of native Windows and Cygwin system calls.  Due to the above change
in Cygwin, there are suddenly two different ideas of the current working
directory, depending of using the Cygwin getcwd call, or the native
GetCurrentDirectory.  The below patch fixes that by keeping them both
always in sync.

Ok to apply?


Thanks,
Corinna

	* win/tclWin32Dll.c (TclWinInit): Set native cwd to Cygwin's cwd.
	* win/tclWinFile.c (TclpObjChdir): Keep native and Cygwin's cwd
	synched.

Index: win/tclWin32Dll.c
===================================================================
RCS file: /cvs/src/src/tcl/win/tclWin32Dll.c,v
retrieving revision 1.10
diff -p -u -r1.10 tclWin32Dll.c
--- win/tclWin32Dll.c	2 Feb 2006 20:02:09 -0000	1.10
+++ win/tclWin32Dll.c	1 Dec 2006 11:44:09 -0000
@@ -13,6 +13,9 @@
  */
 
 #include "tclWinInt.h"
+#ifdef __CYGWIN__
+#include <sys/cygwin.h>
+#endif
 
 /*
  * The following data structures are used when loading the thunking 
@@ -267,6 +270,14 @@ TclWinInit(hInst)
 	panic("Win32s is not a supported platform");	
     }
 
+#ifdef __CYGWIN__
+    {
+      char cwd_posix[MAX_PATH], cwd_win32[MAX_PATH];
+      cygwin_conv_to_full_win32_path (getcwd (cwd_posix, MAX_PATH), cwd_win32);
+      SetCurrentDirectory (cwd_win32);
+    }
+#endif
+
     tclWinProcs = &asciiProcs;
 }
 
Index: win/tclWinFile.c
===================================================================
RCS file: /cvs/src/src/tcl/win/tclWinFile.c,v
retrieving revision 1.11
diff -p -u -r1.11 tclWinFile.c
--- win/tclWinFile.c	12 Feb 2003 04:20:59 -0000	1.11
+++ win/tclWinFile.c	1 Dec 2006 11:44:11 -0000
@@ -1340,14 +1340,16 @@ TclpObjChdir(pathPtr)
 
 
     nativePath = (CONST TCHAR *) Tcl_FSGetNativePath(pathPtr);
+    result = (*tclWinProcs->setCurrentDirectoryProc)(nativePath);
 #ifdef __CYGWIN__
     /* Cygwin chdir only groks POSIX path. */
-    path = Tcl_WinTCharToUtf(nativePath, -1, &ds);
-    cygwin_conv_to_posix_path(path, posixPath);
-    result = (chdir(posixPath) == 0 ? 1 : 0);
-    Tcl_DStringFree(&ds);
-#else /* __CYGWIN__ */
-    result = (*tclWinProcs->setCurrentDirectoryProc)(nativePath);
+    if (result)
+      {
+	path = Tcl_WinTCharToUtf(nativePath, -1, &ds);
+	cygwin_conv_to_posix_path(path, posixPath);
+	(result = (chdir(posixPath) == 0 ? 1 : 0));
+	Tcl_DStringFree(&ds);
+      }
 #endif /* __CYGWIN__ */
 
     if (result == 0) {


-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]