diff options
author | patthoyts <patthoyts@users.sourceforge.net> | 2009-11-24 00:08:26 (GMT) |
---|---|---|
committer | patthoyts <patthoyts@users.sourceforge.net> | 2009-11-24 00:08:26 (GMT) |
commit | c48d854865fb1aa7c418cb6cd4ef39b5d7d0332f (patch) | |
tree | 0ab7b5ec1d21a7bbdbb2570e926240e6c1037388 /win/tclWinFile.c | |
parent | 77d958cdf70019e4a515d2752fff18018f8ee18b (diff) | |
download | tcl-c48d854865fb1aa7c418cb6cd4ef39b5d7d0332f.zip tcl-c48d854865fb1aa7c418cb6cd4ef39b5d7d0332f.tar.gz tcl-c48d854865fb1aa7c418cb6cd4ef39b5d7d0332f.tar.bz2 |
[Bug 2893771] Teach [file stat] to handle locked files.
This stops [file exists] from returning false for files that exist but are locked by
resorting to FindFirstFile when GetFileAttributes fails.
Diffstat (limited to 'win/tclWinFile.c')
-rw-r--r-- | win/tclWinFile.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 46c8489..25e1eac 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinFile.c,v 1.98 2009/03/18 17:08:11 dgp Exp $ + * RCS: @(#) $Id: tclWinFile.c,v 1.99 2009/11/24 00:08:27 patthoyts Exp $ */ /* #define _WIN32_WINNT 0x0500 */ @@ -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; |