Skip to content

Commit 5695855

Browse files
committed
Add stat_result.{st_nlink, st_uid, st_gid}
1 parent 9a1caa0 commit 5695855

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

tests/snippets/stdlib_os.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
104104
print(stat_res.st_mode)
105105
print(stat_res.st_ino)
106106
print(stat_res.st_dev)
107+
print(stat_res.st_nlink)
108+
print(stat_res.st_uid)
109+
print(stat_res.st_gid)

vm/src/stdlib/os.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ struct StatResult {
277277
st_mode: u32,
278278
st_ino: u64,
279279
st_dev: u64,
280+
st_nlink: u64,
281+
st_uid: u32,
282+
st_gid: u32,
280283
}
281284

282285
impl PyValue for StatResult {
@@ -299,6 +302,18 @@ impl StatResultRef {
299302
fn st_dev(self, _vm: &VirtualMachine) -> u64 {
300303
self.st_dev
301304
}
305+
306+
fn st_nlink(self, _vm: &VirtualMachine) -> u64 {
307+
self.st_nlink
308+
}
309+
310+
fn st_uid(self, _vm: &VirtualMachine) -> u32 {
311+
self.st_uid
312+
}
313+
314+
fn st_gid(self, _vm: &VirtualMachine) -> u32 {
315+
self.st_gid
316+
}
302317
}
303318

304319
#[cfg(unix)]
@@ -309,6 +324,9 @@ fn os_stat(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
309324
st_mode: meta.st_mode(),
310325
st_ino: meta.st_ino(),
311326
st_dev: meta.st_dev(),
327+
st_nlink: meta.st_nlink(),
328+
st_uid: meta.st_uid(),
329+
st_gid: meta.st_gid(),
312330
}
313331
.into_ref(vm)
314332
.into_object()),
@@ -322,8 +340,11 @@ fn os_stat(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
322340
match fs::metadata(&path.value) {
323341
Ok(meta) => Ok(StatResult {
324342
st_mode: meta.file_attributes(),
325-
st_ino: 0, // TODO: Not implemented in std::os::windows::fs::MetadataExt.
326-
st_dev: 0, // TODO: Not implemented in std::os::windows::fs::MetadataExt.
343+
st_ino: 0, // TODO: Not implemented in std::os::windows::fs::MetadataExt.
344+
st_dev: 0, // TODO: Not implemented in std::os::windows::fs::MetadataExt.
345+
st_nlink: 0, // TODO: Not implemented in std::os::windows::fs::MetadataExt.
346+
st_uid: 0, // 0 on windows
347+
st_gid: 0, // 0 on windows
327348
}
328349
.into_ref(vm)
329350
.into_object()),
@@ -363,6 +384,9 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
363384
"st_mode" => ctx.new_property(StatResultRef::st_mode),
364385
"st_ino" => ctx.new_property(StatResultRef::st_ino),
365386
"st_dev" => ctx.new_property(StatResultRef::st_dev),
387+
"st_nlink" => ctx.new_property(StatResultRef::st_nlink),
388+
"st_uid" => ctx.new_property(StatResultRef::st_uid),
389+
"st_gid" => ctx.new_property(StatResultRef::st_gid),
366390
});
367391

368392
py_module!(vm, "_os", {

0 commit comments

Comments
 (0)