Tcl Source Code

Artifact [2778fa8221]
Login

Artifact 2778fa8221f71cda3b6a15c8a365be3c84de939c:

Attachment "file-stat.patch" to ticket [2893771fff] added by patthoyts 2009-11-07 17:21:23.
Index: win/tclWinFile.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinFile.c,v
retrieving revision 1.98
diff -u -p -r1.98 tclWinFile.c
--- win/tclWinFile.c	18 Mar 2009 17:08:11 -0000	1.98
+++ win/tclWinFile.c	7 Nov 2009 10:14:57 -0000
@@ -247,7 +247,7 @@ WinLink(
      */
 
     attr = tclWinProcs->getFileAttributesProc(linkSourcePath);
-    if (attr != 0xffffffff) {
+    if (attr != INVALID_FILE_ATTRIBUTES) {
 	Tcl_SetErrno(EEXIST);
 	return -1;
     }
@@ -271,7 +271,7 @@ WinLink(
      */
 
     attr = tclWinProcs->getFileAttributesProc(linkTargetPath);
-    if (attr == 0xffffffff) {
+    if (attr == INVALID_FILE_ATTRIBUTES) {
 	/*
 	 * The target doesn't exist.
 	 */
@@ -368,7 +368,7 @@ WinReadLink(
      */
 
     attr = tclWinProcs->getFileAttributesProc(linkSourcePath);
-    if (attr == 0xffffffff) {
+    if (attr == INVALID_FILE_ATTRIBUTES) {
 	/*
 	 * The source doesn't exist.
 	 */
@@ -912,7 +912,7 @@ TclpMatchInDirectory(
 
 	    if (tclWinProcs->getFileAttributesExProc == NULL) {
 		attr = tclWinProcs->getFileAttributesProc(native);
-		if (attr == 0xffffffff) {
+		if (attr == INVALID_FILE_ATTRIBUTES) {
 		    return TCL_OK;
 		}
 	    } else {
@@ -964,7 +964,8 @@ TclpMatchInDirectory(
 	}
 	attr = tclWinProcs->getFileAttributesProc(native);
 
-	if ((attr == 0xffffffff) || ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)) {
+	if ((attr == INVALID_FILE_ATTRIBUTES) 
+	    || ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)) {
 	    return TCL_OK;
 	}
 
@@ -1547,13 +1548,21 @@ NativeAccess(
 
     attr = tclWinProcs->getFileAttributesProc(nativePath);
 
-    if (attr == 0xffffffff) {
+    if (attr == INVALID_FILE_ATTRIBUTES) {
 	/*
-	 * File doesn't exist.
+	 * File might not exist.
 	 */
 
-	TclWinConvertError(GetLastError());
-	return -1;
+	WIN32_FIND_DATAT ffd;
+	HANDLE hFind;
+	hFind = tclWinProcs->findFirstFileProc(nativePath, &ffd);
+	if (hFind != INVALID_HANDLE_VALUE) {
+	    attr = ffd.w.dwFileAttributes;
+	    FindClose(hFind);
+	} else {
+	    TclWinConvertError(GetLastError());
+	    return -1;
+	}
     }
 
     if ((mode & W_OK)
@@ -2093,8 +2102,21 @@ NativeStat(
 
 	if (tclWinProcs->getFileAttributesExProc(nativePath,
 		GetFileExInfoStandard, &data) != TRUE) {
-	    Tcl_SetErrno(ENOENT);
-	    return -1;
+
+	    /*
+	     * We might have just been denied access
+	     */
+	    
+	    WIN32_FIND_DATAT ffd;
+	    HANDLE hFind;
+	    hFind = tclWinProcs->findFirstFileProc(nativePath, &ffd);
+	    if (hFind != INVALID_HANDLE_VALUE) {
+		memcpy(&data, &ffd, sizeof(data));
+		FindClose(hFind);
+	    } else {
+		Tcl_SetErrno(ENOENT);
+		return -1;
+	    }
 	}
 
 	attr = data.dwFileAttributes;