chore: update dependencies and remove unused server modules
This commit is contained in:
committed by
Andrew Phillips (aider)
parent
f2c951ac73
commit
5150e2f478
@@ -41,13 +41,13 @@ pub fn mode_get(
|
||||
if item_id <= 0 {
|
||||
return Err(anyhow!("Invalid item ID: {}", item_id));
|
||||
}
|
||||
|
||||
|
||||
let mut item_path = data_path.clone();
|
||||
item_path.push(item_id.to_string());
|
||||
|
||||
// Determine if we should detect binary data
|
||||
let mut detect_binary = !args.options.force && is_stdout_tty();
|
||||
|
||||
|
||||
// If we're detecting binary and there's binary metadata, check it
|
||||
if detect_binary {
|
||||
let item_meta = crate::db::get_item_meta(conn, &item)?;
|
||||
@@ -65,22 +65,22 @@ pub fn mode_get(
|
||||
|
||||
let compression_type = CompressionType::from_str(&item.compression)?;
|
||||
let compression_engine = get_compression_engine(compression_type)?;
|
||||
|
||||
|
||||
// If we need to detect binary, read first 4KB and check
|
||||
if detect_binary {
|
||||
// Open the file through compression engine to read first 4KB
|
||||
let mut reader = compression_engine.open(item_path.clone())?;
|
||||
let mut buffer = [0u8; 4096];
|
||||
let bytes_read = reader.read(&mut buffer)?;
|
||||
|
||||
|
||||
// Check if this data is binary
|
||||
if is_binary(&buffer[..bytes_read]) {
|
||||
return Err(anyhow!("Refusing to output binary data to TTY, use --force to override"));
|
||||
}
|
||||
|
||||
|
||||
// If not binary, output the data we've read
|
||||
std::io::stdout().write_all(&buffer[..bytes_read])?;
|
||||
|
||||
|
||||
// Continue reading and outputting the rest of the data
|
||||
let mut stdout = std::io::stdout();
|
||||
std::io::copy(&mut reader, &mut stdout)?;
|
||||
@@ -100,14 +100,14 @@ fn is_stdout_tty() -> bool {
|
||||
unsafe {
|
||||
libc::isatty(libc::STDOUT_FILENO) != 0
|
||||
}
|
||||
|
||||
|
||||
#[cfg(windows)]
|
||||
unsafe {
|
||||
let stdout_handle = winapi::um::processenv::GetStdHandle(winapi::um::winbase::STD_OUTPUT_HANDLE);
|
||||
let mut console_mode: winapi::shared::minwindef::DWORD = 0;
|
||||
winapi::um::consoleapi::GetConsoleMode(stdout_handle, &mut console_mode) != 0
|
||||
}
|
||||
|
||||
|
||||
// Fallback for non-unix platforms or if we can't determine
|
||||
#[cfg(not(any(unix, windows)))]
|
||||
false
|
||||
|
||||
Reference in New Issue
Block a user