[Python-checkins] python/dist/src/Modules posixmodule.c, 2.300.8.4,
2.300.8.5
mhammond at users.sourceforge.net
mhammond at users.sourceforge.net
Tue Dec 2 20:21:04 EST 2003
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv12845
Modified Files:
Tag: release23-maint
posixmodule.c
Log Message:
Fix [ 846133 ] os.chmod/os.utime/shutil do not work with unicode filenames
Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.300.8.4
retrieving revision 2.300.8.5
diff -C2 -d -r2.300.8.4 -r2.300.8.5
*** posixmodule.c 31 Oct 2003 10:01:37 -0000 2.300.8.4
--- posixmodule.c 3 Dec 2003 01:21:01 -0000 2.300.8.5
***************
*** 1145,1149 ****
int i;
int res;
! if (!PyArg_ParseTuple(args, "eti", Py_FileSystemDefaultEncoding,
&path, &i))
return NULL;
--- 1145,1167 ----
int i;
int res;
! #ifdef Py_WIN_WIDE_FILENAMES
! if (unicode_file_names()) {
! PyUnicodeObject *po;
! if (PyArg_ParseTuple(args, "Ui|:chmod", &po, &i)) {
! Py_BEGIN_ALLOW_THREADS
! res = _wchmod(PyUnicode_AS_UNICODE(po), i);
! Py_END_ALLOW_THREADS
! if (res < 0)
! return posix_error_with_unicode_filename(
! PyUnicode_AS_UNICODE(po));
! Py_INCREF(Py_None);
! return Py_None;
! }
! /* Drop the argument parsing error as narrow strings
! are also valid. */
! PyErr_Clear();
! }
! #endif /* Py_WIN_WIDE_FILENAMES */
! if (!PyArg_ParseTuple(args, "eti:chmod", Py_FileSystemDefaultEncoding,
&path, &i))
return NULL;
***************
*** 1917,1925 ****
#endif /* HAVE_UTIMES */
! if (!PyArg_ParseTuple(args, "sO:utime", &path, &arg))
return NULL;
if (arg == Py_None) {
/* optional time values not given */
Py_BEGIN_ALLOW_THREADS
res = utime(path, NULL);
Py_END_ALLOW_THREADS
--- 1935,1964 ----
#endif /* HAVE_UTIMES */
! int have_unicode_filename = 0;
! #ifdef Py_WIN_WIDE_FILENAMES
! PyUnicodeObject *obwpath;
! wchar_t *wpath;
! if (unicode_file_names()) {
! if (PyArg_ParseTuple(args, "UO|:utime", &obwpath, &arg)) {
! wpath = PyUnicode_AS_UNICODE(obwpath);
! have_unicode_filename = 1;
! } else
! /* Drop the argument parsing error as narrow strings
! are also valid. */
! PyErr_Clear();
! }
! #endif /* Py_WIN_WIDE_FILENAMES */
!
! if (!have_unicode_filename && \
! !PyArg_ParseTuple(args, "sO:utime", &path, &arg))
return NULL;
if (arg == Py_None) {
/* optional time values not given */
Py_BEGIN_ALLOW_THREADS
+ #ifdef Py_WIN_WIDE_FILENAMES
+ if (have_unicode_filename)
+ res = _wutime(wpath, NULL);
+ else
+ #endif /* Py_WIN_WIDE_FILENAMES */
res = utime(path, NULL);
Py_END_ALLOW_THREADS
***************
*** 1947,1953 ****
#else
Py_BEGIN_ALLOW_THREADS
res = utime(path, UTIME_ARG);
Py_END_ALLOW_THREADS
! #endif
}
if (res < 0)
--- 1986,2000 ----
#else
Py_BEGIN_ALLOW_THREADS
+ #ifdef Py_WIN_WIDE_FILENAMES
+ if (have_unicode_filename)
+ /* utime is OK with utimbuf, but _wutime insists
+ on _utimbuf (the msvc headers assert the
+ underscore version is ansi) */
+ res = _wutime(wpath, (struct _utimbuf *)UTIME_ARG);
+ else
+ #endif /* Py_WIN_WIDE_FILENAMES */
res = utime(path, UTIME_ARG);
Py_END_ALLOW_THREADS
! #endif /* HAVE_UTIMES */
}
if (res < 0)
More information about the Python-checkins
mailing list