From 5a70331359bc92b4db9825df010a92b9d6fe5b3f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 19 Mar 2013 12:43:21 +0000 Subject: [Bug 2893771]: file stat fails on locked files on win32. --- ChangeLog | 5 +++++ tests/fCmd.test | 22 ++++++++++++++++++++++ win/tclWinFile.c | 16 +++++++++++----- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 83954c9..265faa8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-03-19 Jan Nijtmans + + * win/tclWinFile.c: [Bug 2893771]: file stat fails on locked files + on win32. + 2013-03-18 Donal K. Fellows * tests/cmdAH.test (cmdAH-19.12): [Bug 3608360]: Added test to ensure diff --git a/tests/fCmd.test b/tests/fCmd.test index c5ee676..6b054f7 100644 --- a/tests/fCmd.test +++ b/tests/fCmd.test @@ -2407,6 +2407,28 @@ cd [temporaryDirectory] file delete -force abc.link cd [workingDirectory] +test fCmd-30.1 {file writable on 'My Documents'} -setup { + # Get the localized version of the folder name by looking in the registry. + set mydocsname [registry get {HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders} Personal] +} -constraints {win reg} -body { + file writable $mydocsname +} -result 1 +test fCmd-30.2 {file readable on 'NTUSER.DAT'} -constraints {win} -body { + expr {[info exists env(USERPROFILE)] + && [file exists $env(USERPROFILE)/NTUSER.DAT] + && [file readable $env(USERPROFILE)/NTUSER.DAT]} +} -result {1} +test fCmd-30.3 {file readable on 'pagefile.sys'} -constraints {win} -body { + set r {} + if {[info exists env(SystemDrive)]} { + set path $env(SystemDrive)/pagefile.sys + lappend r exists [file exists $path] + lappend r readable [file readable $path] + lappend r stat [catch {file stat $path a} e] $e + } + return $r +} -result {exists 1 readable 0 stat 0 {}} + removeFile abc2.file removeFile abc.file removeDirectory abc2.dir diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 8ea6548..8e41096 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1337,11 +1337,14 @@ NativeAccess( if (attr == 0xffffffff) { /* - * File doesn't exist. + * File might not exist. */ - TclWinConvertError(GetLastError()); - return -1; + DWORD lasterror = GetLastError(); + if (lasterror != ERROR_SHARING_VIOLATION) { + TclWinConvertError(lasterror); + return -1; + } } if (mode == F_OK) { @@ -1889,8 +1892,11 @@ NativeStat(nativePath, statPtr, checkLinks) if((*tclWinProcs->getFileAttributesExProc)(nativePath, GetFileExInfoStandard, &data) != TRUE) { - Tcl_SetErrno(ENOENT); - return -1; + DWORD lasterror = GetLastError(); + if (lasterror != ERROR_SHARING_VIOLATION) { + TclWinConvertError(lasterror); + return -1; + } } -- cgit v0.12 From f02a6bd750b0c1da6b070dc9faf45562fa1c560d Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 19 Mar 2013 13:37:40 +0000 Subject: make sure that [file stat] returns the right data, even for locked files. --- win/tclWinFile.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 8e41096..22fc6f3 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1892,11 +1892,17 @@ NativeStat(nativePath, statPtr, checkLinks) if((*tclWinProcs->getFileAttributesExProc)(nativePath, GetFileExInfoStandard, &data) != TRUE) { + HANDLE hFind; + WIN32_FIND_DATAT ffd; DWORD lasterror = GetLastError(); + if (lasterror != ERROR_SHARING_VIOLATION) { TclWinConvertError(lasterror); return -1; } + hFind = (*tclWinProcs->findFirstFileProc)(nativePath, &ffd); + memcpy(&data, &ffd, sizeof(data)); + FindClose(hFind); } -- cgit v0.12