Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4110dc

Browse files
committed
Issue #9644: Fix the encoding used by os.statvfs(): use the filesystem encoding
with the surrogateescape error handler, instead of UTF-8 in strict mode.
1 parent 8c126d7 commit e4110dc

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

Lib/test/test_os.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,15 @@ def test_open(self):
10571057
f = open(os.path.join(self.dir, fn), 'rb')
10581058
f.close()
10591059

1060+
@unittest.skipUnless(hasattr(os, 'statvfs'),
1061+
"need os.statvfs()")
1062+
def test_statvfs(self):
1063+
# issue #9645
1064+
for fn in self.unicodefn:
1065+
# should not fail with file not found error
1066+
fullname = os.path.join(self.dir, fn)
1067+
os.statvfs(fullname)
1068+
10601069
def test_stat(self):
10611070
for fn in self.unicodefn:
10621071
os.stat(os.path.join(self.dir, fn))

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ Core and Builtins
189189
Library
190190
-------
191191

192+
- Issue #9644: Fix the encoding used by os.statvfs(): use the filesystem
193+
encoding with the surrogateescape error handler, instead of UTF-8 in strict
194+
mode.
195+
192196
- Issue #16819: IDLE method completion now correctly works for bytes literals.
193197

194198
- Issue #9586: Redefine SEM_FAILED on MacOSX to keep compiler happy.

Modules/posixmodule.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6463,18 +6463,22 @@ Perform a statvfs system call on the given path.");
64636463
static PyObject *
64646464
posix_statvfs(PyObject *self, PyObject *args)
64656465
{
6466+
PyObject *opath, *result = NULL;
64666467
char *path;
64676468
int res;
64686469
struct statvfs st;
6469-
if (!PyArg_ParseTuple(args, "s:statvfs", &path))
6470+
if (!PyArg_ParseTuple(args, "O&:statvfs", PyUnicode_FSConverter, &opath))
64706471
return NULL;
6472+
path = PyBytes_AS_STRING(opath);
64716473
Py_BEGIN_ALLOW_THREADS
64726474
res = statvfs(path, &st);
64736475
Py_END_ALLOW_THREADS
64746476
if (res != 0)
6475-
return posix_error_with_filename(path);
6477+
return posix_error_with_allocated_filename(opath);
64766478

6477-
return _pystatvfs_fromstructstatvfs(st);
6479+
result = _pystatvfs_fromstructstatvfs(st);
6480+
Py_DECREF(opath);
6481+
return result;
64786482
}
64796483
#endif /* HAVE_STATVFS */
64806484

0 commit comments

Comments
 (0)