From 42f67a2c059ac26dd042430f030feb6ffb9e0ad4 Mon Sep 17 00:00:00 2001 From: dvkt Date: Sat, 28 Dec 2019 01:13:01 -0800 Subject: [PATCH] shell() --- src/server.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/server.rs b/src/server.rs index a6bb947..f5bdf43 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,13 +1,14 @@ use crate::{Request, Result}; use gophermap::{GopherMenu, ItemType}; use std::{ - fs::{self, File}, + fs, io::prelude::*, io::{BufReader, Read, Write}, net::{TcpListener, TcpStream}, os::unix::fs::PermissionsExt, path::Path, process::Command, + str, }; use threadpool::ThreadPool; @@ -187,7 +188,7 @@ where let path = req.file_path(); let reader = if is_executable(&path) { - sh(&path, &[&req.selector, &req.host, &req.port.to_string()])? + shell(&path, &[&req.query, &req.host, &req.port.to_string()])? } else { fs::read_to_string(path)? }; @@ -247,11 +248,11 @@ fn is_executable(path: &str) -> bool { } /// Run a script and return its output. -fn sh(path: &str, args: &[&str]) -> Result { +fn shell(path: &str, args: &[&str]) -> Result { let output = Command::new(path).args(args).output()?; if output.status.success() { - Ok(std::str::from_utf8(&output.stdout)?.to_string()) + Ok(str::from_utf8(&output.stdout)?.to_string()) } else { - Ok(std::str::from_utf8(&output.stderr)?.to_string()) + Ok(str::from_utf8(&output.stderr)?.to_string()) } }