From: Martin v. Löwis Date: Sun, 15 Oct 2006 08:43:33 +0000 (+0000) Subject: Patch #1576166: Support os.utime for directories on Windows NT+. X-Git-Tag: v2.6a1~2563 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=18aaa568fd98ec6adcd58f65ffb1a9f6943cfe53;p=python Patch #1576166: Support os.utime for directories on Windows NT+. --- diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 984484c4c3..065d32707d 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -223,6 +223,13 @@ class StatAttributeTests(unittest.TestCase): except TypeError: pass + def test_utime_dir(self): + delta = 1000000 + st = os.stat(test_support.TESTFN) + os.utime(test_support.TESTFN, (st.st_atime, st.st_mtime-delta)) + st2 = os.stat(test_support.TESTFN) + self.assertEquals(st2.st_mtime, st.st_mtime-delta) + # Restrict test to Win32, since there is no guarantee other # systems support centiseconds if sys.platform == 'win32': diff --git a/Misc/NEWS b/Misc/NEWS index 1dcd6aad79..9f7705ab08 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -137,6 +137,8 @@ Library Extension Modules ----------------- +- Patch #1576166: Support os.utime for directories on Windows NT+. + - Bug #1548891: The cStringIO.StringIO() constructor now encodes unicode arguments with the system default encoding just like the write() method does, instead of converting it to a raw buffer. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 93d030017d..9e8bf8f5f0 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -2458,7 +2458,8 @@ posix_utime(PyObject *self, PyObject *args) wpath = PyUnicode_AS_UNICODE(obwpath); Py_BEGIN_ALLOW_THREADS hFile = CreateFileW(wpath, FILE_WRITE_ATTRIBUTES, 0, - NULL, OPEN_EXISTING, 0, NULL); + NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, NULL); Py_END_ALLOW_THREADS if (hFile == INVALID_HANDLE_VALUE) return win32_error_unicode("utime", wpath); @@ -2473,7 +2474,8 @@ posix_utime(PyObject *self, PyObject *args) return NULL; Py_BEGIN_ALLOW_THREADS hFile = CreateFileA(apath, FILE_WRITE_ATTRIBUTES, 0, - NULL, OPEN_EXISTING, 0, NULL); + NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, NULL); Py_END_ALLOW_THREADS if (hFile == INVALID_HANDLE_VALUE) { win32_error("utime", apath); @@ -8617,3 +8619,4 @@ INITFUNC(void) } #endif +