Skip to content

Commit 55bd00b

Browse files
committed
Add stat_result.{st_size}
1 parent 5695855 commit 55bd00b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

tests/snippets/stdlib_os.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,5 @@ def __exit__(self, exc_type, exc_val, exc_tb):
107107
print(stat_res.st_nlink)
108108
print(stat_res.st_uid)
109109
print(stat_res.st_gid)
110+
print(stat_res.st_size)
111+
assert stat_res.st_size == len(CONTENT2) + len(CONTENT3)

vm/src/stdlib/os.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ struct StatResult {
280280
st_nlink: u64,
281281
st_uid: u32,
282282
st_gid: u32,
283+
st_size: u64,
283284
}
284285

285286
impl PyValue for StatResult {
@@ -314,6 +315,10 @@ impl StatResultRef {
314315
fn st_gid(self, _vm: &VirtualMachine) -> u32 {
315316
self.st_gid
316317
}
318+
319+
fn st_size(self, _vm: &VirtualMachine) -> u64 {
320+
self.st_size
321+
}
317322
}
318323

319324
#[cfg(unix)]
@@ -327,6 +332,7 @@ fn os_stat(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
327332
st_nlink: meta.st_nlink(),
328333
st_uid: meta.st_uid(),
329334
st_gid: meta.st_gid(),
335+
st_size: meta.st_size(),
330336
}
331337
.into_ref(vm)
332338
.into_object()),
@@ -345,6 +351,7 @@ fn os_stat(path: PyStringRef, vm: &VirtualMachine) -> PyResult {
345351
st_nlink: 0, // TODO: Not implemented in std::os::windows::fs::MetadataExt.
346352
st_uid: 0, // 0 on windows
347353
st_gid: 0, // 0 on windows
354+
st_size: meta.file_size(),
348355
}
349356
.into_ref(vm)
350357
.into_object()),
@@ -387,6 +394,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
387394
"st_nlink" => ctx.new_property(StatResultRef::st_nlink),
388395
"st_uid" => ctx.new_property(StatResultRef::st_uid),
389396
"st_gid" => ctx.new_property(StatResultRef::st_gid),
397+
"st_size" => ctx.new_property(StatResultRef::st_size),
390398
});
391399

392400
py_module!(vm, "_os", {

0 commit comments

Comments
 (0)