mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00

Some checks are pending
ci / build libs (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
Closes #30570 Changes in this PR: - Implement `ino`, `nlink`, and `blocks` properties of `Deno.FileInfo` on Windows. These changes are automatically reflected to the corresponding node stat function. In order to do so, I had to tinker with the [createByteStruct](a3a904da14/ext/fs/30_fs.js (L297)
) function to create another optional int type, apart from `?u64`. It's common for small sized files on Windows (particularly NTFS file system) to have a `Stats.blocks` property of 0, and currently all 0 values with type `?u64` will be coerced into `null` by `createByteStruct`. - Refactor the `BigIntStats` and `Stats` class, to use the same class with Node.js that are provided from [utils.mjs](7f8e488c36/ext/node/polyfills/internal/fs/utils.mjs (L577)
). Also ensures that all properties are not `null` or `undefined`. - Addresses the `prefer-primordials` lint rule.
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
import { lstat, lstatSync } from "node:fs";
|
|
import { fail } from "@std/assert";
|
|
import {
|
|
assertCallbackErrorUncaught,
|
|
assertStats,
|
|
assertStatsBigInt,
|
|
} from "../_test_utils.ts";
|
|
import type { BigIntStats, Stats } from "node:fs";
|
|
|
|
Deno.test({
|
|
name: "ASYNC: get a file Stats (lstat)",
|
|
async fn() {
|
|
const file = Deno.makeTempFileSync();
|
|
await new Promise<Stats>((resolve, reject) => {
|
|
lstat(file, (err, stat) => {
|
|
if (err) reject(err);
|
|
resolve(stat);
|
|
});
|
|
})
|
|
.then((stat) => {
|
|
assertStats(stat, Deno.lstatSync(file));
|
|
}, () => fail())
|
|
.finally(() => {
|
|
Deno.removeSync(file);
|
|
});
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "SYNC: get a file Stats (lstat)",
|
|
fn() {
|
|
const file = Deno.makeTempFileSync();
|
|
assertStats(lstatSync(file), Deno.lstatSync(file));
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "ASYNC: get a file BigInt Stats (lstat)",
|
|
async fn() {
|
|
const file = Deno.makeTempFileSync();
|
|
await new Promise<BigIntStats>((resolve, reject) => {
|
|
lstat(file, { bigint: true }, (err, stat) => {
|
|
if (err) reject(err);
|
|
resolve(stat);
|
|
});
|
|
})
|
|
.then(
|
|
(stat) => assertStatsBigInt(stat, Deno.lstatSync(file)),
|
|
() => fail(),
|
|
)
|
|
.finally(() => Deno.removeSync(file));
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "SYNC: BigInt Stats (lstat)",
|
|
fn() {
|
|
const file = Deno.makeTempFileSync();
|
|
assertStatsBigInt(lstatSync(file, { bigint: true }), Deno.lstatSync(file));
|
|
},
|
|
});
|
|
|
|
Deno.test("[std/node/fs] lstat callback isn't called twice if error is thrown", async () => {
|
|
const tempFile = await Deno.makeTempFile();
|
|
const importUrl = new URL("node:fs", import.meta.url);
|
|
await assertCallbackErrorUncaught({
|
|
prelude: `import { lstat } from ${JSON.stringify(importUrl)}`,
|
|
invocation: `lstat(${JSON.stringify(tempFile)}, `,
|
|
async cleanup() {
|
|
await Deno.remove(tempFile);
|
|
},
|
|
});
|
|
});
|