Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -4834,7 +4834,6 @@ class PathTConverterTests(unittest.TestCase):
('open', False, (os.O_RDONLY,), getattr(os, 'close', None)),
]

@unittest.expectedFailure # TODO: RUSTPYTHON; (AssertionError: TypeError not raised)
def test_path_t_converter(self):
str_filename = os_helper.TESTFN
if os.name == 'nt':
Expand Down Expand Up @@ -5109,7 +5108,6 @@ def test_fspath_protocol_bytes(self):
self.assertEqual(fspath,
os.path.join(os.fsencode(self.path),bytes_filename))

@unittest.expectedFailureIfWindows('TODO: RUSTPYTHON; entry.is_dir() is False')
def test_removed_dir(self):
path = os.path.join(self.path, 'dir')

Expand All @@ -5132,7 +5130,6 @@ def test_removed_dir(self):
self.assertRaises(FileNotFoundError, entry.stat)
self.assertRaises(FileNotFoundError, entry.stat, follow_symlinks=False)

@unittest.expectedFailureIfWindows('TODO: RUSTPYTHON; entry.is_file() is False')
def test_removed_file(self):
entry = self.create_file_entry()
os.unlink(entry.path)
Expand Down
27 changes: 23 additions & 4 deletions crates/vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,32 @@ pub(super) mod _os {
#[cfg(not(unix))]
let ino = None;

let pathval = entry.path();

// On Windows, pre-cache lstat from directory entry metadata
// This allows stat() to return cached data even if file is removed
#[cfg(windows)]
let lstat = {
let cell = OnceCell::new();
if let Ok(stat_struct) =
crate::windows::win32_xstat(pathval.as_os_str(), false)
{
let stat_obj =
StatResultData::from_stat(&stat_struct, vm).to_pyobject(vm);
let _ = cell.set(stat_obj);
}
cell
};
#[cfg(not(windows))]
let lstat = OnceCell::new();

Ok(PyIterReturn::Return(
DirEntry {
file_name: entry.file_name(),
pathval: entry.path(),
pathval,
file_type: entry.file_type(),
mode: zelf.mode,
lstat: OnceCell::new(),
lstat,
stat: OnceCell::new(),
ino: AtomicCell::new(ino),
}
Expand Down Expand Up @@ -974,11 +993,11 @@ pub(super) mod _os {

#[pyfunction]
fn lstat(
file: OsPathOrFd<'_>,
file: OsPath,
dir_fd: DirFd<'_, { STAT_DIR_FD as usize }>,
vm: &VirtualMachine,
) -> PyResult {
stat(file, dir_fd, FollowSymlinks(false), vm)
stat(file.into(), dir_fd, FollowSymlinks(false), vm)
}

fn curdir_inner(vm: &VirtualMachine) -> PyResult<PathBuf> {
Expand Down
Loading