Skip to content

Commit 118be6c

Browse files
author
martin.v.loewis
committed
Patch #1576166: Support os.utime for directories on Windows NT+.
git-svn-id: http://svn.python.org/projects/python/trunk@52335 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 910740b commit 118be6c

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

Lib/test/test_os.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ def test_statvfs_attributes(self):
223223
except TypeError:
224224
pass
225225

226+
def test_utime_dir(self):
227+
delta = 1000000
228+
st = os.stat(test_support.TESTFN)
229+
os.utime(test_support.TESTFN, (st.st_atime, st.st_mtime-delta))
230+
st2 = os.stat(test_support.TESTFN)
231+
self.assertEquals(st2.st_mtime, st.st_mtime-delta)
232+
226233
# Restrict test to Win32, since there is no guarantee other
227234
# systems support centiseconds
228235
if sys.platform == 'win32':

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ Library
137137
Extension Modules
138138
-----------------
139139

140+
- Patch #1576166: Support os.utime for directories on Windows NT+.
141+
140142
- Bug #1548891: The cStringIO.StringIO() constructor now encodes unicode
141143
arguments with the system default encoding just like the write()
142144
method does, instead of converting it to a raw buffer.

Modules/posixmodule.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,8 @@ posix_utime(PyObject *self, PyObject *args)
24582458
wpath = PyUnicode_AS_UNICODE(obwpath);
24592459
Py_BEGIN_ALLOW_THREADS
24602460
hFile = CreateFileW(wpath, FILE_WRITE_ATTRIBUTES, 0,
2461-
NULL, OPEN_EXISTING, 0, NULL);
2461+
NULL, OPEN_EXISTING,
2462+
FILE_FLAG_BACKUP_SEMANTICS, NULL);
24622463
Py_END_ALLOW_THREADS
24632464
if (hFile == INVALID_HANDLE_VALUE)
24642465
return win32_error_unicode("utime", wpath);
@@ -2473,7 +2474,8 @@ posix_utime(PyObject *self, PyObject *args)
24732474
return NULL;
24742475
Py_BEGIN_ALLOW_THREADS
24752476
hFile = CreateFileA(apath, FILE_WRITE_ATTRIBUTES, 0,
2476-
NULL, OPEN_EXISTING, 0, NULL);
2477+
NULL, OPEN_EXISTING,
2478+
FILE_FLAG_BACKUP_SEMANTICS, NULL);
24772479
Py_END_ALLOW_THREADS
24782480
if (hFile == INVALID_HANDLE_VALUE) {
24792481
win32_error("utime", apath);
@@ -8617,3 +8619,4 @@ INITFUNC(void)
86178619
}
86188620
#endif
86198621

8622+

0 commit comments

Comments
 (0)