mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 16:19:12 -05:00
feat(ext/fs): add isBlockDevice, isCharDevice, isFifo, isSocket to FileInfo (#19008)
`isFile`, `isDirectory`, `isSymlink` are defined in `Deno.FileInfo`, but `isBlockDevice`, `isCharacterDevice`, `isFIFO`, `isSocket` are not defined. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
072e2b2fa2
commit
114ec3c1f7
7 changed files with 85 additions and 2 deletions
|
@ -203,6 +203,10 @@ impl<'a> VfsEntryRef<'a> {
|
||||||
gid: 0,
|
gid: 0,
|
||||||
rdev: 0,
|
rdev: 0,
|
||||||
blocks: 0,
|
blocks: 0,
|
||||||
|
is_block_device: false,
|
||||||
|
is_char_device: false,
|
||||||
|
is_fifo: false,
|
||||||
|
is_socket: false,
|
||||||
},
|
},
|
||||||
VfsEntryRef::File(file) => FsStat {
|
VfsEntryRef::File(file) => FsStat {
|
||||||
is_directory: false,
|
is_directory: false,
|
||||||
|
@ -221,6 +225,10 @@ impl<'a> VfsEntryRef<'a> {
|
||||||
gid: 0,
|
gid: 0,
|
||||||
rdev: 0,
|
rdev: 0,
|
||||||
blocks: 0,
|
blocks: 0,
|
||||||
|
is_block_device: false,
|
||||||
|
is_char_device: false,
|
||||||
|
is_fifo: false,
|
||||||
|
is_socket: false,
|
||||||
},
|
},
|
||||||
VfsEntryRef::Symlink(_) => FsStat {
|
VfsEntryRef::Symlink(_) => FsStat {
|
||||||
is_directory: false,
|
is_directory: false,
|
||||||
|
@ -239,6 +247,10 @@ impl<'a> VfsEntryRef<'a> {
|
||||||
gid: 0,
|
gid: 0,
|
||||||
rdev: 0,
|
rdev: 0,
|
||||||
blocks: 0,
|
blocks: 0,
|
||||||
|
is_block_device: false,
|
||||||
|
is_char_device: false,
|
||||||
|
is_fifo: false,
|
||||||
|
is_socket: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4715,7 +4715,7 @@ fn lsp_completions_auto_import() {
|
||||||
"source": "./b.ts",
|
"source": "./b.ts",
|
||||||
"data": {
|
"data": {
|
||||||
"exportName": "foo",
|
"exportName": "foo",
|
||||||
"exportMapKey": "foo|6806|file:///a/b",
|
"exportMapKey": "foo|6810|file:///a/b",
|
||||||
"moduleSpecifier": "./b.ts",
|
"moduleSpecifier": "./b.ts",
|
||||||
"fileName": "file:///a/b.ts"
|
"fileName": "file:///a/b.ts"
|
||||||
},
|
},
|
||||||
|
|
|
@ -307,6 +307,10 @@ Deno.test(
|
||||||
assert(s.rdev === null);
|
assert(s.rdev === null);
|
||||||
assert(s.blksize === null);
|
assert(s.blksize === null);
|
||||||
assert(s.blocks === null);
|
assert(s.blocks === null);
|
||||||
|
assert(s.isBlockDevice === null);
|
||||||
|
assert(s.isCharDevice === null);
|
||||||
|
assert(s.isFifo === null);
|
||||||
|
assert(s.isSocket === null);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -334,5 +338,9 @@ Deno.test(
|
||||||
assert(s.rdev !== null);
|
assert(s.rdev !== null);
|
||||||
assert(s.blksize !== null);
|
assert(s.blksize !== null);
|
||||||
assert(s.blocks !== null);
|
assert(s.blocks !== null);
|
||||||
|
assert(!s.isBlockDevice);
|
||||||
|
assert(!s.isCharDevice);
|
||||||
|
assert(!s.isFifo);
|
||||||
|
assert(!s.isSocket);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
16
cli/tsc/dts/lib.deno.ns.d.ts
vendored
16
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -3122,6 +3122,22 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* _Linux/Mac OS only._ */
|
* _Linux/Mac OS only._ */
|
||||||
blocks: number | null;
|
blocks: number | null;
|
||||||
|
/** True if this is info for a block device.
|
||||||
|
*
|
||||||
|
* _Linux/Mac OS only._ */
|
||||||
|
isBlockDevice: boolean | null;
|
||||||
|
/** True if this is info for a char device.
|
||||||
|
*
|
||||||
|
* _Linux/Mac OS only._ */
|
||||||
|
isCharDevice: boolean | null;
|
||||||
|
/** True if this is info for a fifo.
|
||||||
|
*
|
||||||
|
* _Linux/Mac OS only._ */
|
||||||
|
isFifo: boolean | null;
|
||||||
|
/** True if this is info for a socket.
|
||||||
|
*
|
||||||
|
* _Linux/Mac OS only._ */
|
||||||
|
isSocket: boolean | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolves to the absolute normalized path, with symbolic links resolved.
|
/** Resolves to the absolute normalized path, with symbolic links resolved.
|
||||||
|
|
|
@ -245,6 +245,7 @@ async function rename(oldpath, newpath) {
|
||||||
// high u32 | low u32
|
// high u32 | low u32
|
||||||
//
|
//
|
||||||
// 4. ?u64 converts a zero u64 value to JS null on Windows.
|
// 4. ?u64 converts a zero u64 value to JS null on Windows.
|
||||||
|
// ?bool converts a false bool 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;
|
||||||
|
@ -273,7 +274,15 @@ function createByteStruct(types) {
|
||||||
}] + view[${offset + 3}] * 2**32),`;
|
}] + view[${offset + 3}] * 2**32),`;
|
||||||
offset += 2;
|
offset += 2;
|
||||||
} else {
|
} else {
|
||||||
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),`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
offset += 2;
|
offset += 2;
|
||||||
}
|
}
|
||||||
|
@ -299,6 +308,10 @@ const { 0: statStruct, 1: statBuf } = createByteStruct({
|
||||||
rdev: "?u64",
|
rdev: "?u64",
|
||||||
blksize: "?u64",
|
blksize: "?u64",
|
||||||
blocks: "?u64",
|
blocks: "?u64",
|
||||||
|
isBlockDevice: "?bool",
|
||||||
|
isCharDevice: "?bool",
|
||||||
|
isFifo: "?bool",
|
||||||
|
isSocket: "?bool",
|
||||||
});
|
});
|
||||||
|
|
||||||
function parseFileInfo(response) {
|
function parseFileInfo(response) {
|
||||||
|
@ -322,6 +335,10 @@ function parseFileInfo(response) {
|
||||||
rdev: unix ? response.rdev : null,
|
rdev: unix ? response.rdev : null,
|
||||||
blksize: unix ? response.blksize : null,
|
blksize: unix ? response.blksize : null,
|
||||||
blocks: unix ? response.blocks : null,
|
blocks: unix ? response.blocks : null,
|
||||||
|
isBlockDevice: unix ? response.isBlockDevice : null,
|
||||||
|
isCharDevice: unix ? response.isCharDevice : null,
|
||||||
|
isFifo: unix ? response.isFifo : null,
|
||||||
|
isSocket: unix ? response.isSocket : null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1596,6 +1596,10 @@ create_struct_writer! {
|
||||||
rdev: u64,
|
rdev: u64,
|
||||||
blksize: u64,
|
blksize: u64,
|
||||||
blocks: u64,
|
blocks: u64,
|
||||||
|
is_block_device: bool,
|
||||||
|
is_char_device: bool,
|
||||||
|
is_fifo: bool,
|
||||||
|
is_socket: bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1623,6 +1627,10 @@ impl From<FsStat> for SerializableStat {
|
||||||
rdev: stat.rdev,
|
rdev: stat.rdev,
|
||||||
blksize: stat.blksize,
|
blksize: stat.blksize,
|
||||||
blocks: stat.blocks,
|
blocks: stat.blocks,
|
||||||
|
is_block_device: stat.is_block_device,
|
||||||
|
is_char_device: stat.is_char_device,
|
||||||
|
is_fifo: stat.is_fifo,
|
||||||
|
is_socket: stat.is_socket,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
ext/io/fs.rs
22
ext/io/fs.rs
|
@ -89,6 +89,10 @@ pub struct FsStat {
|
||||||
pub rdev: u64,
|
pub rdev: u64,
|
||||||
pub blksize: u64,
|
pub blksize: u64,
|
||||||
pub blocks: u64,
|
pub blocks: u64,
|
||||||
|
pub is_block_device: bool,
|
||||||
|
pub is_char_device: bool,
|
||||||
|
pub is_fifo: bool,
|
||||||
|
pub is_socket: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FsStat {
|
impl FsStat {
|
||||||
|
@ -107,6 +111,20 @@ impl FsStat {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! unix_or_false {
|
||||||
|
($member:ident) => {{
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::os::unix::fs::FileTypeExt;
|
||||||
|
metadata.file_type().$member()
|
||||||
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
{
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_msec(maybe_time: Result<SystemTime, io::Error>) -> Option<u64> {
|
fn to_msec(maybe_time: Result<SystemTime, io::Error>) -> Option<u64> {
|
||||||
match maybe_time {
|
match maybe_time {
|
||||||
|
@ -139,6 +157,10 @@ impl FsStat {
|
||||||
rdev: unix_or_zero!(rdev),
|
rdev: unix_or_zero!(rdev),
|
||||||
blksize: unix_or_zero!(blksize),
|
blksize: unix_or_zero!(blksize),
|
||||||
blocks: unix_or_zero!(blocks),
|
blocks: unix_or_zero!(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),
|
||||||
|
is_socket: unix_or_false!(is_socket),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue