This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_1686475 of test_os & pagefile.sys
Type: behavior Stage: resolved
Components: Extension Modules, Tests Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, abkhd, ajaksu2, brian.curtin, ezio.melotti, loewis, tim.golden
Priority: normal Keywords: patch

Created on 2007-04-28 06:35 by abkhd, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_os.patch abkhd, 2007-04-28 06:35 Patch for test_os.py to fix problem
test_1686475.patch abkhd, 2007-04-30 01:52 Fix for posixmodule's handling of windows' error review
Messages (8)
msg52536 - (view) Author: A.B., Khalid (abkhd) Date: 2007-04-28 06:35
test_1686475 of test_os appears to rely on the
existence of "pagefile.sys" on the C drive like so:

def test_1686475(self):
    # Verify that an open file can be stat'ed
    try:
        os.stat(r"c:\pagefile.sys")
    except WindowsError, e:
        if e == 2: # file does not exist; cannot run test
            return
        self.fail("Could not stat pagefile.sys")


But since pagefile.sys may not be on every C
drive and since the exception object e is not a numeric then that test is probably going to fail if the pagefile.sys does not exist where it is expected.

In such a case Windows returns "[Error 5] Access is denied: 'c:\\pagefile.sys'". So we need to test if e.winerror == 5 to skip this and return without failing.

Patch "test_os.patch" is attached. 

By the way, I see the same problem in the trunk, so maybe this need to be applied there as well.
msg52537 - (view) Author: A.B., Khalid (abkhd) Date: 2007-04-30 01:52
Please see http://www.python.org/sf/1686475 for reference.


Martin,

I think you should be checking for ERROR_ACCESS_DENIED not ERROR_SHARING_VIOLATION as you do in your patch to r54685 and r54686. The attached posixmodule patch fixes this issue for me on MinGW. Can you try it out?
File Added: test_1686475.patch
msg52538 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-04-30 05:16
Why should I not check for ERROR_SHARING_VIOLATION? The OP complains that he sees an error "The process cannot access the file because it is being used by another process" in 2.5.0, and can stat the file in 2.4. So it is clearly ERROR_SHARING_VIOLATION that is being returned (also on the system on which I developed the patch).
msg52539 - (view) Author: A.B., Khalid (abkhd) Date: 2007-04-30 09:07
I had thought that the file was opened exclusively by Windows
and so the latter denied access to it (including sharing). 
However, it might be worth a while to note how others handle 
this problem. 

Please see ntfs.c of MIT/GNU Scheme:
http://www.koders.com/c/fid3A61BD3B46FA62F5E9F99E5860DCAE5BC2B7FA2C.aspx

and ntfs.h of the same project:
http://www.koders.com/c/fid5FA9A6766ABABAAB4DC09266CA61866F8270A139.aspx


They actually test for both errors in addtion to ERROR_DRIVE_LOCKED to determine if stat has worked or not.

Regards,
Khalid




More references:
http://www.supportnet.de/stat/2002/7/id98848.asp
http://www.cygwin.com/ml/cygwin/2000-01/msg00274.html
http://ftp.gnu.org/gnu/mit-scheme/stable.pkg/7.7.1/changelog.txt
msg52540 - (view) Author: A.B., Khalid (abkhd) Date: 2007-04-30 10:01
Another source seems to suggest that the error message will
differ depending on the Windows version. I think the error 
message might be more related to the underlying file system. 

Hence since my C drive is formated as FAT WinXP might be 
reporting attempted access to the locked pagefile.sys as ERROR_ACCESS_DENIED, however, in other machines where the 
C drive could be formated as an NTFS then the error message 
will be changed to SHARING_ERROR_VIOLATION. 

This makes sense because pagefile.sys seems to be opened 
exclusively by Windows in either case. The error differs 
depending on the capability of the file system. And so one 
would be expected to test for both errors to see if stat 
worked.


Regards,
Khalid



Reference [Search of ERROR_SHARING_VIOLATION] in syscalls.cc of Cygwin:
http://www.koders.com/cpp/fid05B16888E9827D2766C45C718ED8620BC82B4DCE.aspx
pagefile.sys
msg84715 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-03-30 23:25
The Modules/posixmodule.c patch needs tests.
msg116675 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-09-17 16:05
@Brian/Tim the attached patches have not been applied, what do you make of this one?
msg183204 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-02-28 05:28
Now the test (see Lib/test/test_os.py:470) has been changed to:

try:
    os.stat(r"c:\pagefile.sys")
except FileNotFoundError:
    pass # file does not exist; cannot run test
except OSError as e:
    self.fail("Could not stat pagefile.sys")

so this should work properly now.

I can't find the code changed by the second patch in Modules/posixmodule.c, so I'm going to close this issue as out of date.
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 44909
2013-02-28 05:28:15ezio.melottisetstatus: open -> closed

nosy: + ezio.melotti
messages: + msg183204

resolution: out of date
stage: test needed -> resolved
2010-09-17 16:05:29BreamoreBoysetnosy: + tim.golden, brian.curtin, BreamoreBoy
messages: + msg116675
components: + Extension Modules, - Windows
2009-03-30 23:25:32ajaksu2settype: behavior
title: test_1686475 of test_os & pagefile.sys -> test_1686475 of test_os & pagefile.sys
components: + Windows

nosy: + ajaksu2
versions: + Python 2.6, Python 3.0, - Python 2.5
messages: + msg84715
stage: test needed
2007-04-28 06:35:31abkhdcreate