result = os.stat(fname)
self.assertNotEqual(result.st_size, 0)
+ @unittest.skipUnless(sys.platform == "win32", "Win32 specific tests")
+ def test_stat_block_device(self):
+ # bpo-38030: os.stat fails for block devices
+ # Test a filename like "//./C:"
+ fname = "//./" + os.path.splitdrive(os.getcwd())[0]
+ result = os.stat(fname)
+ self.assertEqual(result.st_mode, stat.S_IFBLK)
+
class UtimeTests(unittest.TestCase):
def setUp(self):
case ERROR_INVALID_PARAMETER:
case ERROR_INVALID_FUNCTION:
case ERROR_NOT_SUPPORTED:
- retval = -1;
+ /* Volumes and physical disks are block devices, e.g.
+ \\.\C: and \\.\PhysicalDrive0. */
+ memset(result, 0, sizeof(*result));
+ result->st_mode = 0x6000; /* S_IFBLK */
goto cleanup;
}
- /* Volumes and physical disks are block devices, e.g.
- \\.\C: and \\.\PhysicalDrive0. */
- memset(result, 0, sizeof(*result));
- result->st_mode = 0x6000; /* S_IFBLK */
+ retval = -1;
goto cleanup;
}
}
cleanup:
if (hFile != INVALID_HANDLE_VALUE) {
- CloseHandle(hFile);
+ /* Preserve last error if we are failing */
+ error = retval ? GetLastError() : 0;
+ if (!CloseHandle(hFile)) {
+ retval = -1;
+ } else if (retval) {
+ /* Restore last error */
+ SetLastError(error);
+ }
}
return retval;