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
6 changes: 3 additions & 3 deletions cli/rt/file_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,13 +1449,13 @@ impl FileBackedVfsMetadata {
blksize: 0,
size: self.len,
dev: 0,
ino: 0,
ino: None,
mode: 0,
nlink: 0,
nlink: None,
uid: 0,
gid: 0,
rdev: 0,
blocks: 0,
blocks: None,
is_block_device: false,
is_char_device: false,
is_fifo: false,
Expand Down
14 changes: 5 additions & 9 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3054,17 +3054,15 @@ declare namespace Deno {
ctime: Date | null;
/** ID of the device containing the file. */
dev: number;
/** Inode number.
*
* _Linux/Mac OS only._ */
/** Corresponds to the inode number on Unix systems. On Windows, this is
* the file index number that is unique within a volume. This may not be
* available on all platforms. */
ino: number | null;
/** The underlying raw `st_mode` bits that contain the standard Unix
* permissions for this file/directory.
*/
mode: number | null;
/** Number of hard links pointing to this file.
*
* _Linux/Mac OS only._ */
/** Number of hard links pointing to this file. */
nlink: number | null;
/** User ID of the owner of this file.
*
Expand All @@ -3082,9 +3080,7 @@ declare namespace Deno {
*
* _Linux/Mac OS only._ */
blksize: number | null;
/** Number of blocks allocated to the file, in 512-byte units.
*
* _Linux/Mac OS only._ */
/** Number of blocks allocated to the file, in 512-byte units. */
blocks: number | null;
/** True if this is info for a block device.
*
Expand Down
38 changes: 26 additions & 12 deletions ext/fs/30_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async function rename(oldpath, newpath) {
// Extract the FsStat object from the encoded buffer.
// See `runtime/ops/fs.rs` for the encoder.
//
// This is not a general purpose decoder. There are 4 types:
// This is not a general purpose decoder. There are 5 types:
//
// 1. date
// offset += 4
Expand All @@ -295,6 +295,14 @@ async function rename(oldpath, newpath) {
//
// 4. ?u64 converts a zero u64 value to JS null on Windows.
// ?bool converts a false bool value to JS null on Windows.
//
// 5. !u64 persists the u64 value even if it's zero,
// only if the corresponding "_set" field is set to true.
// Unlike ?u64, this is OS agnostic.
// offset += 4
// 1/0 | extra padding | high u32 | low u32
// if value[0] == 1, u64 else null
//
function createByteStruct(types) {
// types can be "date", "bool" or "u64".
let offset = 0;
Expand All @@ -304,26 +312,32 @@ function createByteStruct(types) {
for (let i = 0; i < typeEntries.length; ++i) {
let { 0: name, 1: type } = typeEntries[i];

const optional = StringPrototypeStartsWith(type, "?");
if (optional) type = StringPrototypeSlice(type, 1);
const optionalLoose = StringPrototypeStartsWith(type, "?");
const optionalStrict = StringPrototypeStartsWith(type, "!");
if (optionalLoose || optionalStrict) type = StringPrototypeSlice(type, 1);

if (type == "u64") {
if (!optional) {
if (!optionalLoose && !optionalStrict) {
str += `${name}: view[${offset}] + view[${offset + 1}] * 2**32,`;
} else {
} else if (optionalLoose) {
str += `${name}: (unix ? (view[${offset}] + view[${
offset + 1
}] * 2**32) : (view[${offset}] + view[${
offset + 1
}] * 2**32) || null),`;
} else {
str += `${name}: (view[${offset}] === 1 ? (view[${offset + 2}] + view[${
offset + 3
}] * 2**32) : null),`;
offset += 2;
}
} else if (type == "date") {
str += `${name}: view[${offset}] === 0 ? null : new Date(view[${
offset + 2
}] + view[${offset + 3}] * 2**32),`;
offset += 2;
} else {
if (!optional) {
if (!optionalLoose) {
str += `${name}: !!(view[${offset}] + view[${offset + 1}] * 2**32),`;
} else {
str += `${name}: (unix ? !!((view[${offset}] + view[${
Expand All @@ -350,14 +364,14 @@ const { 0: statStruct, 1: statBuf } = createByteStruct({
birthtime: "date",
ctime: "date",
dev: "u64",
ino: "?u64",
ino: "!u64",
mode: "u64",
nlink: "?u64",
nlink: "!u64",
uid: "?u64",
gid: "?u64",
rdev: "?u64",
blksize: "?u64",
blocks: "?u64",
blocks: "!u64",
isBlockDevice: "?bool",
isCharDevice: "?bool",
isFifo: "?bool",
Expand All @@ -383,13 +397,13 @@ function parseFileInfo(response) {
ctime: response.ctimeSet === true ? new Date(Number(response.ctime)) : null,
dev: response.dev,
mode: response.mode,
ino: unix ? response.ino : null,
nlink: unix ? response.nlink : null,
ino: response.inoSet ? Number(response.ino) : null,
nlink: response.nlinkSet ? response.nlink : null,
uid: unix ? response.uid : null,
gid: unix ? response.gid : null,
rdev: unix ? response.rdev : null,
blksize: unix ? response.blksize : null,
blocks: unix ? response.blocks : null,
blocks: response.blocksSet ? response.blocks : null,
isBlockDevice: unix ? response.isBlockDevice : null,
isCharDevice: unix ? response.isCharDevice : null,
isFifo: unix ? response.isFifo : null,
Expand Down
17 changes: 13 additions & 4 deletions ext/fs/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2087,15 +2087,21 @@ create_struct_writer! {
birthtime: u64,
ctime_set: bool,
ctime: u64,
// Following are only valid under Unix.
// Stats below are platform dependent.
// On Unix, they are always available.
// On Windows, the `*_set` fields are used
// to indicate if the corresponding field is resolved.
dev: u64,
ino_set: bool,
ino: u64,
mode: u32,
nlink_set: bool,
nlink: u64,
uid: u32,
gid: u32,
rdev: u64,
blksize: u64,
blocks_set: bool,
blocks: u64,
is_block_device: bool,
is_char_device: bool,
Expand All @@ -2122,14 +2128,17 @@ impl From<FsStat> for SerializableStat {
ctime: stat.ctime.unwrap_or(0),

dev: stat.dev,
ino: stat.ino,
ino_set: stat.ino.is_some(),
ino: stat.ino.unwrap_or(0),
mode: stat.mode,
nlink: stat.nlink,
nlink_set: stat.nlink.is_some(),
nlink: stat.nlink.unwrap_or(0),
uid: stat.uid,
gid: stat.gid,
rdev: stat.rdev,
blksize: stat.blksize,
blocks: stat.blocks,
blocks_set: stat.blocks.is_some(),
blocks: stat.blocks.unwrap_or(0),
is_block_device: stat.is_block_device,
is_char_device: stat.is_char_device,
is_fifo: stat.is_fifo,
Expand Down
26 changes: 20 additions & 6 deletions ext/io/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ pub struct FsStat {
pub ctime: Option<u64>,

pub dev: u64,
pub ino: u64,
pub ino: Option<u64>,
pub mode: u32,
pub nlink: u64,
pub nlink: Option<u64>,
pub uid: u32,
pub gid: u32,
pub rdev: u64,
pub blksize: u64,
pub blocks: u64,
pub blocks: Option<u64>,
pub is_block_device: bool,
pub is_char_device: bool,
pub is_fifo: bool,
Expand All @@ -127,6 +127,20 @@ pub struct FsStat {

impl FsStat {
pub fn from_std(metadata: std::fs::Metadata) -> Self {
macro_rules! unix_some_or_none {
($member:ident) => {{
#[cfg(unix)]
{
use std::os::unix::fs::MetadataExt;
Some(metadata.$member())
}
#[cfg(not(unix))]
{
None
}
}};
}

macro_rules! unix_or_zero {
($member:ident) => {{
#[cfg(unix)]
Expand Down Expand Up @@ -190,14 +204,14 @@ impl FsStat {
ctime: get_ctime(unix_or_zero!(ctime)),

dev: unix_or_zero!(dev),
ino: unix_or_zero!(ino),
ino: unix_some_or_none!(ino),
mode: unix_or_zero!(mode),
nlink: unix_or_zero!(nlink),
nlink: unix_some_or_none!(nlink),
uid: unix_or_zero!(uid),
gid: unix_or_zero!(gid),
rdev: unix_or_zero!(rdev),
blksize: unix_or_zero!(blksize),
blocks: unix_or_zero!(blocks),
blocks: unix_some_or_none!(blocks),
is_block_device: unix_or_false!(is_block_device),
is_char_device: unix_or_false!(is_char_device),
is_fifo: unix_or_false!(is_fifo),
Expand Down
6 changes: 6 additions & 0 deletions ext/io/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,12 @@ pub fn stat_extra(file: &std::fs::File, fsstat: &mut FsStat) -> FsResult<()> {
| ((libc::S_IREAD | libc::S_IWRITE) >> 6))
as u32;
}

/* The on-disk allocation size in 512-byte units. */
fsstat.blocks =
Some(file_info.StandardInformation.AllocationSize as u64 >> 9);
fsstat.ino = Some(file_info.InternalInformation.IndexNumber as u64);
fsstat.nlink = Some(file_info.StandardInformation.NumberOfLinks as u64);
}

Ok(())
Expand Down
Loading
Loading