mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
BREAKING(ext/fs): FileInfo.dev is defined on Windows (#18237)
Addresses feedback from https://github.com/denoland/deno/pull/18073#issuecomment-1471480385. Reverts changes to `FileInfo` fields that are not available on Windows making them `null`. Only `FileInfo.dev` is non-null.
This commit is contained in:
parent
8efda832e2
commit
3f031ad9af
3 changed files with 58 additions and 43 deletions
|
@ -291,7 +291,7 @@ Deno.test(
|
||||||
ignore: Deno.build.os !== "windows",
|
ignore: Deno.build.os !== "windows",
|
||||||
permissions: { read: true, write: true },
|
permissions: { read: true, write: true },
|
||||||
},
|
},
|
||||||
function statUnixFieldsOnWindows() {
|
function statNoUnixFields() {
|
||||||
const enc = new TextEncoder();
|
const enc = new TextEncoder();
|
||||||
const data = enc.encode("Hello");
|
const data = enc.encode("Hello");
|
||||||
const tempDir = Deno.makeTempDirSync();
|
const tempDir = Deno.makeTempDirSync();
|
||||||
|
@ -299,14 +299,14 @@ Deno.test(
|
||||||
Deno.writeFileSync(filename, data, { mode: 0o666 });
|
Deno.writeFileSync(filename, data, { mode: 0o666 });
|
||||||
const s = Deno.statSync(filename);
|
const s = Deno.statSync(filename);
|
||||||
assert(s.dev !== 0);
|
assert(s.dev !== 0);
|
||||||
assert(s.ino === 0);
|
assert(s.ino === null);
|
||||||
assert(s.mode === 0);
|
assert(s.mode === null);
|
||||||
assert(s.nlink === 0);
|
assert(s.nlink === null);
|
||||||
assert(s.uid === 0);
|
assert(s.uid === null);
|
||||||
assert(s.gid === 0);
|
assert(s.gid === null);
|
||||||
assert(s.rdev === 0);
|
assert(s.rdev === null);
|
||||||
assert(s.blksize === 0);
|
assert(s.blksize === null);
|
||||||
assert(s.blocks === 0);
|
assert(s.blocks === null);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
30
cli/tsc/dts/lib.deno.ns.d.ts
vendored
30
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -3082,37 +3082,37 @@ declare namespace Deno {
|
||||||
dev: number;
|
dev: number;
|
||||||
/** Inode number.
|
/** Inode number.
|
||||||
*
|
*
|
||||||
* _Linux/Mac OS only, always returns 0 on Windows_ */
|
* _Linux/Mac OS only._ */
|
||||||
ino: number;
|
ino: number | null;
|
||||||
/** **UNSTABLE**: Match behavior with Go on Windows for `mode`.
|
/** **UNSTABLE**: Match behavior with Go on Windows for `mode`.
|
||||||
*
|
*
|
||||||
* The underlying raw `st_mode` bits that contain the standard Unix
|
* The underlying raw `st_mode` bits that contain the standard Unix
|
||||||
* permissions for this file/directory. */
|
* permissions for this file/directory. */
|
||||||
mode: number;
|
mode: number | null;
|
||||||
/** Number of hard links pointing to this file.
|
/** Number of hard links pointing to this file.
|
||||||
*
|
*
|
||||||
* _Linux/Mac OS only, always returns 0 on Windows_ */
|
* _Linux/Mac OS only._ */
|
||||||
nlink: number;
|
nlink: number | null;
|
||||||
/** User ID of the owner of this file.
|
/** User ID of the owner of this file.
|
||||||
*
|
*
|
||||||
* _Linux/Mac OS only, always returns 0 on Windows_ */
|
* _Linux/Mac OS only._ */
|
||||||
uid: number;
|
uid: number | null;
|
||||||
/** Group ID of the owner of this file.
|
/** Group ID of the owner of this file.
|
||||||
*
|
*
|
||||||
* _Linux/Mac OS only, always returns 0 on Windows_ */
|
* _Linux/Mac OS only._ */
|
||||||
gid: number;
|
gid: number | null;
|
||||||
/** Device ID of this file.
|
/** Device ID of this file.
|
||||||
*
|
*
|
||||||
* _Linux/Mac OS only, always returns 0 on Windows_ */
|
* _Linux/Mac OS only._ */
|
||||||
rdev: number;
|
rdev: number | null;
|
||||||
/** Blocksize for filesystem I/O.
|
/** Blocksize for filesystem I/O.
|
||||||
*
|
*
|
||||||
* _Linux/Mac OS only, always returns 0 on Windows_ */
|
* _Linux/Mac OS only._ */
|
||||||
blksize: number;
|
blksize: number | null;
|
||||||
/** Number of blocks allocated to the file, in 512-byte units.
|
/** Number of blocks allocated to the file, in 512-byte units.
|
||||||
*
|
*
|
||||||
* _Linux/Mac OS only, always returns 0 on Windows_ */
|
* _Linux/Mac OS only._ */
|
||||||
blocks: number;
|
blocks: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolves to the absolute normalized path, with symbolic links resolved.
|
/** Resolves to the absolute normalized path, with symbolic links resolved.
|
||||||
|
|
|
@ -211,16 +211,30 @@ async function rename(oldpath, newpath) {
|
||||||
// 3. u64
|
// 3. u64
|
||||||
// offset += 2
|
// offset += 2
|
||||||
// high u32 | low u32
|
// high u32 | low u32
|
||||||
|
//
|
||||||
|
// 4. ?u64 converts a zero u64 value to JS null on Windows.
|
||||||
function createByteStruct(types) {
|
function createByteStruct(types) {
|
||||||
// types can be "date", "bool" or "u64".
|
// types can be "date", "bool" or "u64".
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
let str = "return {";
|
let str =
|
||||||
|
'const unix = Deno.build.os === "darwin" || Deno.build.os === "linux"; return {';
|
||||||
const typeEntries = ObjectEntries(types);
|
const typeEntries = ObjectEntries(types);
|
||||||
for (let i = 0; i < typeEntries.length; ++i) {
|
for (let i = 0; i < typeEntries.length; ++i) {
|
||||||
const { 0: name, 1: type } = typeEntries[i];
|
let { 0: name, 1: type } = typeEntries[i];
|
||||||
|
|
||||||
|
const optional = type.startsWith("?");
|
||||||
|
if (optional) type = type.slice(1);
|
||||||
|
|
||||||
if (type == "u64") {
|
if (type == "u64") {
|
||||||
str += `${name}: view[${offset}] + view[${offset + 1}] * 2**32,`;
|
if (!optional) {
|
||||||
|
str += `${name}: view[${offset}] + view[${offset + 1}] * 2**32,`;
|
||||||
|
} else {
|
||||||
|
str += `${name}: (unix ? (view[${offset}] + view[${
|
||||||
|
offset + 1
|
||||||
|
}] * 2**32) : (view[${offset}] + view[${
|
||||||
|
offset + 1
|
||||||
|
}] * 2**32) || null),`;
|
||||||
|
}
|
||||||
} else if (type == "date") {
|
} else if (type == "date") {
|
||||||
str += `${name}: view[${offset}] === 0 ? null : new Date(view[${
|
str += `${name}: view[${offset}] === 0 ? null : new Date(view[${
|
||||||
offset + 2
|
offset + 2
|
||||||
|
@ -245,17 +259,18 @@ const { 0: statStruct, 1: statBuf } = createByteStruct({
|
||||||
atime: "date",
|
atime: "date",
|
||||||
birthtime: "date",
|
birthtime: "date",
|
||||||
dev: "u64",
|
dev: "u64",
|
||||||
ino: "u64",
|
ino: "?u64",
|
||||||
mode: "u64",
|
mode: "?u64",
|
||||||
nlink: "u64",
|
nlink: "?u64",
|
||||||
uid: "u64",
|
uid: "?u64",
|
||||||
gid: "u64",
|
gid: "?u64",
|
||||||
rdev: "u64",
|
rdev: "?u64",
|
||||||
blksize: "u64",
|
blksize: "?u64",
|
||||||
blocks: "u64",
|
blocks: "?u64",
|
||||||
});
|
});
|
||||||
|
|
||||||
function parseFileInfo(response) {
|
function parseFileInfo(response) {
|
||||||
|
const unix = core.build.os === "darwin" || core.build.os === "linux";
|
||||||
return {
|
return {
|
||||||
isFile: response.isFile,
|
isFile: response.isFile,
|
||||||
isDirectory: response.isDirectory,
|
isDirectory: response.isDirectory,
|
||||||
|
@ -267,14 +282,14 @@ function parseFileInfo(response) {
|
||||||
? new Date(response.birthtime)
|
? new Date(response.birthtime)
|
||||||
: null,
|
: null,
|
||||||
dev: response.dev,
|
dev: response.dev,
|
||||||
ino: response.ino,
|
ino: unix ? response.ino : null,
|
||||||
mode: response.mode,
|
mode: unix ? response.mode : null,
|
||||||
nlink: response.nlink,
|
nlink: unix ? response.nlink : null,
|
||||||
uid: response.uid,
|
uid: unix ? response.uid : null,
|
||||||
gid: response.gid,
|
gid: unix ? response.gid : null,
|
||||||
rdev: response.rdev,
|
rdev: unix ? response.rdev : null,
|
||||||
blksize: response.blksize,
|
blksize: unix ? response.blksize : null,
|
||||||
blocks: response.blocks,
|
blocks: unix ? response.blocks : null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue