Skip to content

Commit 4a1f63b

Browse files
authored
Revert "fix(ext/node): fs.stat and fs.statSync compatibility (#30… (#30741)
…637)" This reverts commit 432761a. The tests are causing flakes on Windows
1 parent a6663b0 commit 4a1f63b

File tree

13 files changed

+467
-639
lines changed

13 files changed

+467
-639
lines changed

cli/rt/file_system.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,13 +1443,13 @@ impl FileBackedVfsMetadata {
14431443
blksize: 0,
14441444
size: self.len,
14451445
dev: 0,
1446-
ino: None,
1446+
ino: 0,
14471447
mode: 0,
1448-
nlink: None,
1448+
nlink: 0,
14491449
uid: 0,
14501450
gid: 0,
14511451
rdev: 0,
1452-
blocks: None,
1452+
blocks: 0,
14531453
is_block_device: false,
14541454
is_char_device: false,
14551455
is_fifo: false,

cli/tsc/dts/lib.deno.ns.d.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,15 +3054,17 @@ declare namespace Deno {
30543054
ctime: Date | null;
30553055
/** ID of the device containing the file. */
30563056
dev: number;
3057-
/** Corresponds to the inode number on Unix systems. On Windows, this is
3058-
* the file index number that is unique within a volume. This may not be
3059-
* available on all platforms. */
3057+
/** Inode number.
3058+
*
3059+
* _Linux/Mac OS only._ */
30603060
ino: number | null;
30613061
/** The underlying raw `st_mode` bits that contain the standard Unix
30623062
* permissions for this file/directory.
30633063
*/
30643064
mode: number | null;
3065-
/** Number of hard links pointing to this file. */
3065+
/** Number of hard links pointing to this file.
3066+
*
3067+
* _Linux/Mac OS only._ */
30663068
nlink: number | null;
30673069
/** User ID of the owner of this file.
30683070
*
@@ -3080,7 +3082,9 @@ declare namespace Deno {
30803082
*
30813083
* _Linux/Mac OS only._ */
30823084
blksize: number | null;
3083-
/** Number of blocks allocated to the file, in 512-byte units. */
3085+
/** Number of blocks allocated to the file, in 512-byte units.
3086+
*
3087+
* _Linux/Mac OS only._ */
30843088
blocks: number | null;
30853089
/** True if this is info for a block device.
30863090
*

ext/fs/30_fs.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ async function rename(oldpath, newpath) {
277277
// Extract the FsStat object from the encoded buffer.
278278
// See `runtime/ops/fs.rs` for the encoder.
279279
//
280-
// This is not a general purpose decoder. There are 5 types:
280+
// This is not a general purpose decoder. There are 4 types:
281281
//
282282
// 1. date
283283
// offset += 4
@@ -294,14 +294,6 @@ async function rename(oldpath, newpath) {
294294
//
295295
// 4. ?u64 converts a zero u64 value to JS null on Windows.
296296
// ?bool converts a false bool value to JS null on Windows.
297-
//
298-
// 5. !u64 persists the u64 value even if it's zero,
299-
// only if the corresponding "_set" field is set to true.
300-
// Unlike ?u64, this is OS agnostic.
301-
// offset += 4
302-
// 1/0 | extra padding | high u32 | low u32
303-
// if value[0] == 1, u64 else null
304-
//
305297
function createByteStruct(types) {
306298
// types can be "date", "bool" or "u64".
307299
let offset = 0;
@@ -311,32 +303,26 @@ function createByteStruct(types) {
311303
for (let i = 0; i < typeEntries.length; ++i) {
312304
let { 0: name, 1: type } = typeEntries[i];
313305

314-
const optionalLoose = StringPrototypeStartsWith(type, "?");
315-
const optionalStrict = StringPrototypeStartsWith(type, "!");
316-
if (optionalLoose || optionalStrict) type = StringPrototypeSlice(type, 1);
306+
const optional = StringPrototypeStartsWith(type, "?");
307+
if (optional) type = StringPrototypeSlice(type, 1);
317308

318309
if (type == "u64") {
319-
if (!optionalLoose && !optionalStrict) {
310+
if (!optional) {
320311
str += `${name}: view[${offset}] + view[${offset + 1}] * 2**32,`;
321-
} else if (optionalLoose) {
312+
} else {
322313
str += `${name}: (unix ? (view[${offset}] + view[${
323314
offset + 1
324315
}] * 2**32) : (view[${offset}] + view[${
325316
offset + 1
326317
}] * 2**32) || null),`;
327-
} else {
328-
str += `${name}: (view[${offset}] === 1 ? (view[${offset + 2}] + view[${
329-
offset + 3
330-
}] * 2**32) : null),`;
331-
offset += 2;
332318
}
333319
} else if (type == "date") {
334320
str += `${name}: view[${offset}] === 0 ? null : new Date(view[${
335321
offset + 2
336322
}] + view[${offset + 3}] * 2**32),`;
337323
offset += 2;
338324
} else {
339-
if (!optionalLoose) {
325+
if (!optional) {
340326
str += `${name}: !!(view[${offset}] + view[${offset + 1}] * 2**32),`;
341327
} else {
342328
str += `${name}: (unix ? !!((view[${offset}] + view[${
@@ -363,14 +349,14 @@ const { 0: statStruct, 1: statBuf } = createByteStruct({
363349
birthtime: "date",
364350
ctime: "date",
365351
dev: "u64",
366-
ino: "!u64",
352+
ino: "?u64",
367353
mode: "u64",
368-
nlink: "!u64",
354+
nlink: "?u64",
369355
uid: "?u64",
370356
gid: "?u64",
371357
rdev: "?u64",
372358
blksize: "?u64",
373-
blocks: "!u64",
359+
blocks: "?u64",
374360
isBlockDevice: "?bool",
375361
isCharDevice: "?bool",
376362
isFifo: "?bool",
@@ -396,13 +382,13 @@ function parseFileInfo(response) {
396382
ctime: response.ctimeSet === true ? new Date(Number(response.ctime)) : null,
397383
dev: response.dev,
398384
mode: response.mode,
399-
ino: response.inoSet ? response.ino : null,
400-
nlink: response.nlinkSet ? response.nlink : null,
385+
ino: unix ? response.ino : null,
386+
nlink: unix ? response.nlink : null,
401387
uid: unix ? response.uid : null,
402388
gid: unix ? response.gid : null,
403389
rdev: unix ? response.rdev : null,
404390
blksize: unix ? response.blksize : null,
405-
blocks: response.blocksSet ? response.blocks : null,
391+
blocks: unix ? response.blocks : null,
406392
isBlockDevice: unix ? response.isBlockDevice : null,
407393
isCharDevice: unix ? response.isCharDevice : null,
408394
isFifo: unix ? response.isFifo : null,

ext/fs/ops.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,21 +2059,15 @@ create_struct_writer! {
20592059
birthtime: u64,
20602060
ctime_set: bool,
20612061
ctime: u64,
2062-
// Stats below are platform dependent.
2063-
// On Unix, they are always available.
2064-
// On Windows, the `*_set` fields are used
2065-
// to indicate if the corresponding field is resolved.
2062+
// Following are only valid under Unix.
20662063
dev: u64,
2067-
ino_set: bool,
20682064
ino: u64,
20692065
mode: u32,
2070-
nlink_set: bool,
20712066
nlink: u64,
20722067
uid: u32,
20732068
gid: u32,
20742069
rdev: u64,
20752070
blksize: u64,
2076-
blocks_set: bool,
20772071
blocks: u64,
20782072
is_block_device: bool,
20792073
is_char_device: bool,
@@ -2100,17 +2094,14 @@ impl From<FsStat> for SerializableStat {
21002094
ctime: stat.ctime.unwrap_or(0),
21012095

21022096
dev: stat.dev,
2103-
ino_set: stat.ino.is_some(),
2104-
ino: stat.ino.unwrap_or(0),
2097+
ino: stat.ino,
21052098
mode: stat.mode,
2106-
nlink_set: stat.nlink.is_some(),
2107-
nlink: stat.nlink.unwrap_or(0),
2099+
nlink: stat.nlink,
21082100
uid: stat.uid,
21092101
gid: stat.gid,
21102102
rdev: stat.rdev,
21112103
blksize: stat.blksize,
2112-
blocks_set: stat.blocks.is_some(),
2113-
blocks: stat.blocks.unwrap_or(0),
2104+
blocks: stat.blocks,
21142105
is_block_device: stat.is_block_device,
21152106
is_char_device: stat.is_char_device,
21162107
is_fifo: stat.is_fifo,

ext/fs/std_fs.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,12 +1005,6 @@ fn stat_extra(file: &std::fs::File, fsstat: &mut FsStat) -> FsResult<()> {
10051005
| ((libc::S_IREAD | libc::S_IWRITE) >> 6))
10061006
as u32;
10071007
}
1008-
1009-
/* The on-disk allocation size in 512-byte units. */
1010-
fsstat.blocks =
1011-
Some(file_info.StandardInformation.AllocationSize as u64 >> 9);
1012-
fsstat.ino = Some(file_info.InternalInformation.IndexNumber as u64);
1013-
fsstat.nlink = Some(file_info.StandardInformation.NumberOfLinks as u64);
10141008
}
10151009

10161010
Ok(())

ext/io/fs.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ pub struct FsStat {
110110
pub ctime: Option<u64>,
111111

112112
pub dev: u64,
113-
pub ino: Option<u64>,
113+
pub ino: u64,
114114
pub mode: u32,
115-
pub nlink: Option<u64>,
115+
pub nlink: u64,
116116
pub uid: u32,
117117
pub gid: u32,
118118
pub rdev: u64,
119119
pub blksize: u64,
120-
pub blocks: Option<u64>,
120+
pub blocks: u64,
121121
pub is_block_device: bool,
122122
pub is_char_device: bool,
123123
pub is_fifo: bool,
@@ -126,20 +126,6 @@ pub struct FsStat {
126126

127127
impl FsStat {
128128
pub fn from_std(metadata: std::fs::Metadata) -> Self {
129-
macro_rules! unix_some_or_none {
130-
($member:ident) => {{
131-
#[cfg(unix)]
132-
{
133-
use std::os::unix::fs::MetadataExt;
134-
Some(metadata.$member())
135-
}
136-
#[cfg(not(unix))]
137-
{
138-
None
139-
}
140-
}};
141-
}
142-
143129
macro_rules! unix_or_zero {
144130
($member:ident) => {{
145131
#[cfg(unix)]
@@ -203,14 +189,14 @@ impl FsStat {
203189
ctime: get_ctime(unix_or_zero!(ctime)),
204190

205191
dev: unix_or_zero!(dev),
206-
ino: unix_some_or_none!(ino),
192+
ino: unix_or_zero!(ino),
207193
mode: unix_or_zero!(mode),
208-
nlink: unix_some_or_none!(nlink),
194+
nlink: unix_or_zero!(nlink),
209195
uid: unix_or_zero!(uid),
210196
gid: unix_or_zero!(gid),
211197
rdev: unix_or_zero!(rdev),
212198
blksize: unix_or_zero!(blksize),
213-
blocks: unix_some_or_none!(blocks),
199+
blocks: unix_or_zero!(blocks),
214200
is_block_device: unix_or_false!(is_block_device),
215201
is_char_device: unix_or_false!(is_char_device),
216202
is_fifo: unix_or_false!(is_fifo),

0 commit comments

Comments
 (0)