mirror of
https://github.com/denoland/deno.git
synced 2025-01-12 09:03:42 -05:00
chore(cli): remove atty crate (#20275)
Removes a crate with an outstanding vulnerability.
This commit is contained in:
parent
9e31f9452e
commit
c272d26ae8
10 changed files with 37 additions and 39 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -786,7 +786,6 @@ name = "deno"
|
||||||
version = "1.36.3"
|
version = "1.36.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"atty",
|
|
||||||
"base32",
|
"base32",
|
||||||
"base64 0.13.1",
|
"base64 0.13.1",
|
||||||
"bincode",
|
"bincode",
|
||||||
|
|
|
@ -62,7 +62,6 @@ eszip = "=0.50.0"
|
||||||
napi_sym.workspace = true
|
napi_sym.workspace = true
|
||||||
|
|
||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
atty.workspace = true
|
|
||||||
base32 = "=0.4.0"
|
base32 = "=0.4.0"
|
||||||
base64.workspace = true
|
base64.workspace = true
|
||||||
bincode = "=1.3.3"
|
bincode = "=1.3.3"
|
||||||
|
|
3
cli/cache/cache_db.rs
vendored
3
cli/cache/cache_db.rs
vendored
|
@ -9,6 +9,7 @@ use deno_runtime::deno_webstorage::rusqlite::Connection;
|
||||||
use deno_runtime::deno_webstorage::rusqlite::OptionalExtension;
|
use deno_runtime::deno_webstorage::rusqlite::OptionalExtension;
|
||||||
use deno_runtime::deno_webstorage::rusqlite::Params;
|
use deno_runtime::deno_webstorage::rusqlite::Params;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
|
use std::io::IsTerminal;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -261,7 +262,7 @@ impl CacheDB {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Failed, try deleting it
|
// Failed, try deleting it
|
||||||
let is_tty = atty::is(atty::Stream::Stderr);
|
let is_tty = std::io::stderr().is_terminal();
|
||||||
log::log!(
|
log::log!(
|
||||||
if is_tty { log::Level::Warn } else { log::Level::Trace },
|
if is_tty { log::Level::Warn } else { log::Level::Trace },
|
||||||
"Could not initialize cache database '{}', deleting and retrying... ({err:?})",
|
"Could not initialize cache database '{}', deleting and retrying... ({err:?})",
|
||||||
|
|
|
@ -23,6 +23,7 @@ use once_cell::sync::Lazy;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::io::IsTerminal;
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -210,7 +211,7 @@ pub fn check_for_upgrades(
|
||||||
|
|
||||||
// Print a message if an update is available
|
// Print a message if an update is available
|
||||||
if let Some(upgrade_version) = update_checker.should_prompt() {
|
if let Some(upgrade_version) = update_checker.should_prompt() {
|
||||||
if log::log_enabled!(log::Level::Info) && atty::is(atty::Stream::Stderr) {
|
if log::log_enabled!(log::Level::Info) && std::io::stderr().is_terminal() {
|
||||||
if version::is_canary() {
|
if version::is_canary() {
|
||||||
eprint!(
|
eprint!(
|
||||||
"{} ",
|
"{} ",
|
||||||
|
|
|
@ -5,6 +5,7 @@ use deno_core::parking_lot::Mutex;
|
||||||
use deno_core::unsync::spawn_blocking;
|
use deno_core::unsync::spawn_blocking;
|
||||||
use deno_runtime::ops::tty::ConsoleSize;
|
use deno_runtime::ops::tty::ConsoleSize;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
use std::io::IsTerminal;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ static INTERNAL_STATE: Lazy<Arc<Mutex<InternalState>>> = Lazy::new(|| {
|
||||||
});
|
});
|
||||||
|
|
||||||
static IS_TTY_WITH_CONSOLE_SIZE: Lazy<bool> = Lazy::new(|| {
|
static IS_TTY_WITH_CONSOLE_SIZE: Lazy<bool> = Lazy::new(|| {
|
||||||
atty::is(atty::Stream::Stderr)
|
std::io::stderr().is_terminal()
|
||||||
&& console_size()
|
&& console_size()
|
||||||
.map(|s| s.cols > 0 && s.rows > 0)
|
.map(|s| s.cols > 0 && s.rows > 0)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
|
|
|
@ -16,6 +16,7 @@ use notify::RecommendedWatcher;
|
||||||
use notify::RecursiveMode;
|
use notify::RecursiveMode;
|
||||||
use notify::Watcher;
|
use notify::Watcher;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::io::IsTerminal;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -98,7 +99,7 @@ pub struct PrintConfig {
|
||||||
|
|
||||||
fn create_print_after_restart_fn(clear_screen: bool) -> impl Fn() {
|
fn create_print_after_restart_fn(clear_screen: bool) -> impl Fn() {
|
||||||
move || {
|
move || {
|
||||||
if clear_screen && atty::is(atty::Stream::Stderr) {
|
if clear_screen && std::io::stderr().is_terminal() {
|
||||||
eprint!("{CLEAR_SCREEN}");
|
eprint!("{CLEAR_SCREEN}");
|
||||||
}
|
}
|
||||||
info!(
|
info!(
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use atty;
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::io::IsTerminal;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use termcolor::Ansi;
|
use termcolor::Ansi;
|
||||||
use termcolor::Color::Ansi256;
|
use termcolor::Color::Ansi256;
|
||||||
|
@ -25,7 +25,7 @@ use termcolor::ColorChoice;
|
||||||
static NO_COLOR: Lazy<bool> =
|
static NO_COLOR: Lazy<bool> =
|
||||||
Lazy::new(|| std::env::var_os("NO_COLOR").is_some());
|
Lazy::new(|| std::env::var_os("NO_COLOR").is_some());
|
||||||
|
|
||||||
static IS_TTY: Lazy<bool> = Lazy::new(|| atty::is(atty::Stream::Stdout));
|
static IS_TTY: Lazy<bool> = Lazy::new(|| std::io::stdout().is_terminal());
|
||||||
|
|
||||||
pub fn is_tty() -> bool {
|
pub fn is_tty() -> bool {
|
||||||
*IS_TTY
|
*IS_TTY
|
||||||
|
|
|
@ -4,7 +4,6 @@ const ops = core.ops;
|
||||||
const primordials = globalThis.__bootstrap.primordials;
|
const primordials = globalThis.__bootstrap.primordials;
|
||||||
const {
|
const {
|
||||||
Uint32Array,
|
Uint32Array,
|
||||||
Uint8Array,
|
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
const size = new Uint32Array(2);
|
const size = new Uint32Array(2);
|
||||||
|
@ -14,10 +13,8 @@ function consoleSize() {
|
||||||
return { columns: size[0], rows: size[1] };
|
return { columns: size[0], rows: size[1] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const isattyBuffer = new Uint8Array(1);
|
|
||||||
function isatty(rid) {
|
function isatty(rid) {
|
||||||
ops.op_isatty(rid, isattyBuffer);
|
return ops.op_isatty(rid);
|
||||||
return !!isattyBuffer[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { consoleSize, isatty };
|
export { consoleSize, isatty };
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
|
use std::io::IsTerminal;
|
||||||
|
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
|
use deno_core::op2;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
|
use deno_core::ResourceHandle;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use deno_core::ResourceId;
|
use deno_core::ResourceId;
|
||||||
|
@ -162,32 +165,27 @@ fn op_stdin_set_raw(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op(fast)]
|
#[op2(fast)]
|
||||||
fn op_isatty(
|
fn op_isatty(state: &mut OpState, rid: u32) -> Result<bool, AnyError> {
|
||||||
state: &mut OpState,
|
let handle = state.resource_table.get_handle(rid)?;
|
||||||
rid: u32,
|
// TODO(mmastrac): this can migrate to the deno_core implementation when it lands
|
||||||
out: &mut [u8],
|
Ok(match handle {
|
||||||
) -> Result<(), AnyError> {
|
ResourceHandle::Fd(fd) if handle.is_valid() => {
|
||||||
let raw_fd = state.resource_table.get_fd(rid)?;
|
#[cfg(windows)]
|
||||||
#[cfg(windows)]
|
{
|
||||||
{
|
// SAFETY: The resource remains open for the for the duration of borrow_raw
|
||||||
use winapi::shared::minwindef::FALSE;
|
unsafe {
|
||||||
use winapi::um::consoleapi;
|
std::os::windows::io::BorrowedHandle::borrow_raw(fd).is_terminal()
|
||||||
|
}
|
||||||
let handle = raw_fd;
|
}
|
||||||
let mut test_mode: DWORD = 0;
|
#[cfg(unix)]
|
||||||
// If I cannot get mode out of console, it is not a console.
|
{
|
||||||
out[0] =
|
// SAFETY: The resource remains open for the for the duration of borrow_raw
|
||||||
// SAFETY: Windows API
|
unsafe { std::os::fd::BorrowedFd::borrow_raw(fd).is_terminal() }
|
||||||
unsafe { consoleapi::GetConsoleMode(handle, &mut test_mode) != FALSE }
|
}
|
||||||
as u8;
|
}
|
||||||
}
|
_ => false,
|
||||||
#[cfg(unix)]
|
})
|
||||||
{
|
|
||||||
// SAFETY: Posix API
|
|
||||||
out[0] = unsafe { libc::isatty(raw_fd as libc::c_int) == 1 } as u8;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op(fast)]
|
#[op(fast)]
|
||||||
|
|
|
@ -6,6 +6,7 @@ use deno_core::parking_lot::Mutex;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
|
use std::io::IsTerminal;
|
||||||
use std::io::StderrLock;
|
use std::io::StderrLock;
|
||||||
use std::io::StdinLock;
|
use std::io::StdinLock;
|
||||||
use std::io::Write as IoWrite;
|
use std::io::Write as IoWrite;
|
||||||
|
@ -84,7 +85,7 @@ impl PermissionPrompter for TtyPrompter {
|
||||||
api_name: Option<&str>,
|
api_name: Option<&str>,
|
||||||
is_unary: bool,
|
is_unary: bool,
|
||||||
) -> PromptResponse {
|
) -> PromptResponse {
|
||||||
if !atty::is(atty::Stream::Stdin) || !atty::is(atty::Stream::Stderr) {
|
if !std::io::stdin().is_terminal() || !std::io::stderr().is_terminal() {
|
||||||
return PromptResponse::Deny;
|
return PromptResponse::Deny;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue