Skip to content

Commit

Permalink
Merge pull request kpcyrd#229 from kpcyrd/bump
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
kpcyrd authored Jul 17, 2022
2 parents 3ea88d9 + febb39a commit 231d329
Show file tree
Hide file tree
Showing 17 changed files with 657 additions and 620 deletions.
1,136 changes: 584 additions & 552 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sqlite-bundled = ["libsqlite3-sys/bundled"]
[dependencies]
sn0int-common = { version="0.13.0", path="sn0int-common" }
sn0int-std = { version="=0.24.2", path="sn0int-std" }
rustyline = "9.0"
rustyline = "10.0"
log = "0.4"
env_logger = "0.9"
hlua-badtouch = "0.4"
Expand Down Expand Up @@ -93,13 +93,13 @@ os-version = "0.2"
caps = "0.5"
#syscallz = { path="../syscallz-rs" }
syscallz = "0.16"
nix = "0.23"
nix = "0.24"

[target.'cfg(target_os="openbsd")'.dependencies]
pledge = "0.4"
unveil = "0.3"

[dev-dependencies]
#boxxy = { path = "../boxxy-rs" }
boxxy = "0.12"
boxxy = "0.13"
tempfile = "3.0"
6 changes: 3 additions & 3 deletions sn0int-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ pem = "1"
url = "2.0"
tungstenite = { version = "0.13", default-features = false }
kuchiki = "0.8.0"
maxminddb = "0.22"
maxminddb = "0.23"
x509-parser = "0.13"
der-parser = "7"
der-parser = "8"
publicsuffix = { version="2", default-features=false }
xml-rs = "0.8"
geo = "0.19"
geo = "0.20"
bytes = "0.4"
base64 = "0.13"
chrono = { version = "0.4", features = ["serde"] }
Expand Down
4 changes: 3 additions & 1 deletion sn0int-std/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rand::distributions::Alphanumeric;
use serde::{Serialize, Deserialize};
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::fmt::Write;
use std::iter;
use std::net::SocketAddr;
use std::ops::Deref;
Expand Down Expand Up @@ -251,7 +252,8 @@ impl HttpRequest {
if !cookies.is_empty() {
cookies += "; ";
}
cookies.push_str(&format!("{}={}", key, value));
// it's a write to a String, so panic if re-allocation fails is fine
write!(cookies, "{}={}", key, value).expect("out of memory");
}

if !cookies.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion sn0int-std/src/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn decode(x: &str) -> Result<AnyLuaValue> {
}

#[inline]
fn append_text(stack: &mut Vec<XmlElement>, text: String) {
fn append_text(stack: &mut [XmlElement], text: String) {
if let Some(tail) = stack.last_mut() {
if let Some(prev) = tail.text.as_mut() {
prev.push_str(&text);
Expand Down
5 changes: 3 additions & 2 deletions src/cal/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::cal::{ActivityGrade, DateArg};
use crate::models::*;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::fmt::Write;

const MONTH_LINES: i32 = 7;

Expand Down Expand Up @@ -223,7 +224,7 @@ impl DateSpec {
let start = Utc.ymd(*year, *month, 1);
let days = days_in_month(*year, *month) as u32;

w.push_str(&format!("{:^21}\n", start.format("%B %Y")));
writeln!(w, "{:^21}", start.format("%B %Y")).expect("out of memory");
w.push_str(" Su Mo Tu We Th Fr Sa\n");

let mut cur_week_day = start.weekday();
Expand All @@ -244,7 +245,7 @@ impl DateSpec {
} else {
w.push(' ');
}
w.push_str(&format!("{:2}", cur_day));
write!(w, "{:2}", cur_day).expect("out of memory");
week_written += 3;
w.push_str("\x1b[0m");

Expand Down
3 changes: 2 additions & 1 deletion src/cal/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use chrono::prelude::*;
use crate::cal::{ActivityGrade, DateArg};
use crate::models::*;
use std::collections::HashMap;
use std::fmt::Write;

const MIN_PER_DAY: u32 = 1440;

Expand Down Expand Up @@ -156,7 +157,7 @@ impl DateTimeSpec {
// add legend
w.push_str(&" ".repeat(11));
for x in 0..24 {
w.push_str(&format!("{:02}", x));
write!(w, "{:02}", x).expect("out of memory");

for i in 0..ctx.hour_width() {
if i >= 2 {
Expand Down
22 changes: 11 additions & 11 deletions src/cmd/notify_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::errors::*;

use crate::cmd::Cmd;
use crate::engine::Module;
// use crate::models::*;
use crate::notify::{self, Notification};
use crate::options::{self, Opt};
use crate::shell::Shell;
use crate::term;
use sn0int_std::ratelimits::Ratelimiter;
use std::fmt::Write;
use structopt::StructOpt;
use structopt::clap::AppSettings;

Expand Down Expand Up @@ -52,19 +52,19 @@ pub struct ExecArgs {
}

fn print_summary(module: &Module, sent: usize, errors: usize) {
let mut out = if sent == 1 {
String::from("Sent 1 notification")
} else {
format!("Sent {} notifications", sent)
};
let mut out = if sent == 1 {
String::from("Sent 1 notification")
} else {
format!("Sent {} notifications", sent)
};

out.push_str(&format!(" with {}", module.canonical()));
write!(out, " with {}", module.canonical()).expect("out of memory");

if errors > 0 {
out.push_str(&format!(" ({} errors)", errors));
}
if errors > 0 {
write!(out, " ({} errors)", errors).expect("out of memory");
}

term::info(&out);
term::info(&out);
}

fn send(args: SendArgs, rl: &mut Shell) -> Result<()> {
Expand Down
7 changes: 4 additions & 3 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use diesel::expression::SqlLiteral;
use diesel::expression::sql_literal::sql;
use diesel::sql_types::Bool;
use diesel::prelude::*;
use std::fmt::Write;
use strum_macros::{EnumString, IntoStaticStr};
use crate::autonoscope::{RuleSet, RuleType};
use crate::models::*;
Expand Down Expand Up @@ -502,14 +503,14 @@ impl Filter {
for arg in args {
if ["=", "!=", "<", ">", "<=", ">=", "like"].contains(&arg.to_lowercase().as_str()) {
expect_value = true;
query += &format!(" {}", arg);
write!(query, " {}", arg)?;
continue;
}

if let Some(idx) = arg.find('=') {
if idx != 0 {
let (key, value) = arg.split_at(idx);
query += &format!(" {} = {}", key, Self::escape(&value[1..]));
write!(query, " {} = {}", key, Self::escape(&value[1..]))?;
continue;
}
}
Expand All @@ -519,7 +520,7 @@ impl Filter {
query.push_str(&Self::escape(arg));
expect_value = false;
} else {
query += &format!(" {}", arg);
write!(query, " {}", arg)?;
}
}
debug!("Parsed query: {:?}", query);
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(clippy::too_many_arguments)]
#![allow(clippy::type_complexity)]
#![allow(clippy::large_enum_variant)]
// because of diesel
#![allow(clippy::extra_unused_lifetimes)]

#![warn(unused_extern_crates)]
use hlua_badtouch as hlua;
Expand Down
12 changes: 6 additions & 6 deletions src/repl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ pub struct Repl<'a> {
}

impl<'a> Repl<'a> {
pub fn new(lua: Lua<'a>, state: Arc<LuaState>) -> Repl<'a> {
let rl = Readline::with(ReplCompleter::default());
Repl {
pub fn new(lua: Lua<'a>, state: Arc<LuaState>) -> Result<Repl<'a>> {
let rl = Readline::with(ReplCompleter::default())?;
Ok(Repl {
rl,
lua,
state,
}
})
}

fn update_globals(&mut self) {
Expand Down Expand Up @@ -63,7 +63,7 @@ impl<'a> Repl<'a> {
Ok(val) => {
if val != AnyLuaValue::LuaNil {
let mut out = String::new();
format_lua(&mut out, &val);
format_lua(&mut out, &val).expect("out of memory");
println!("{}", out);
}
if let Some(err) = self.state.last_error() {
Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn run(config: &Config) -> Result<()> {

let tx = DummyIpcChild::create();
let (lua, state) = ctx::ctx(env, tx);
let mut repl = Repl::new(lua, state);
let mut repl = Repl::new(lua, state)?;

println!(r#":: sn0int v{} lua repl
Assign variables with `a = sn0int_version()` and `return a` to print
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::errors::*;
use crate::engine::ctx::State;
use crate::engine::structs::byte_array;
use crate::hlua::{self, AnyLuaValue};
use std::fmt::Write;
use std::sync::Arc;


// TODO: consider deprecating this function, replace with hex_{en,de}code and hex_custom_{en,de}code
pub fn hex(lua: &mut hlua::Lua, state: Arc<dyn State>) {
lua.set("hex", hlua::function1(move |bytes: AnyLuaValue| -> Result<String> {
Expand All @@ -15,7 +15,7 @@ pub fn hex(lua: &mut hlua::Lua, state: Arc<dyn State>) {
let mut out = String::new();

for b in bytes {
out += &format!("{:02x}", b);
write!(out, "{:02x}", b).expect("out of memory");
}

out
Expand Down
27 changes: 15 additions & 12 deletions src/runtime/logger.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use crate::errors::*;
use crate::engine::ctx::State;
use crate::hlua::{self, AnyLuaValue};
use std::fmt::Write;
use std::sync::Arc;


pub fn format_lua(out: &mut String, x: &AnyLuaValue) {
pub fn format_lua(out: &mut String, x: &AnyLuaValue) -> Result<()> {
match *x {
AnyLuaValue::LuaNil => out.push_str("null"),
AnyLuaValue::LuaString(ref x) => out.push_str(&format!("{:?}", x)),
AnyLuaValue::LuaNumber(ref x) => out.push_str(&format!("{:?}", x)),
AnyLuaValue::LuaAnyString(ref x) => out.push_str(&format!("{:?}", x.0)),
AnyLuaValue::LuaBoolean(ref x) => out.push_str(&format!("{:?}", x)),
AnyLuaValue::LuaString(ref x) => write!(out, "{:?}", x)?,
AnyLuaValue::LuaNumber(ref x) => write!(out, "{:?}", x)?,
AnyLuaValue::LuaAnyString(ref x) => write!(out, "{:?}", x.0)?,
AnyLuaValue::LuaBoolean(ref x) => write!(out, "{:?}", x)?,
AnyLuaValue::LuaArray(ref x) => {
out.push('{');
let mut first = true;
Expand All @@ -20,33 +21,35 @@ pub fn format_lua(out: &mut String, x: &AnyLuaValue) {
}

let mut key = String::new();
format_lua(&mut key, k);
format_lua(&mut key, k)?;

let mut value = String::new();
format_lua(&mut value, v);
format_lua(&mut value, v)?;

out.push_str(&format!("{}: {}", key, value));
write!(out, "{}: {}", key, value)?;

first = false;
}
out.push('}');
},
AnyLuaValue::LuaOther => out.push_str("LuaOther"),
}

Ok(())
}

pub fn info(lua: &mut hlua::Lua, state: Arc<dyn State>) {
lua.set("info", hlua::function1(move |val: AnyLuaValue| {
let mut out = String::new();
format_lua(&mut out, &val);
format_lua(&mut out, &val).expect("out of memory");
state.info(out);
}))
}

pub fn debug(lua: &mut hlua::Lua, state: Arc<dyn State>) {
lua.set("debug", hlua::function1(move |val: AnyLuaValue| {
let mut out = String::new();
format_lua(&mut out, &val);
format_lua(&mut out, &val).expect("out of memory");
state.debug(out);
}))
}
Expand Down Expand Up @@ -79,7 +82,7 @@ pub fn print(lua: &mut hlua::Lua, _: Arc<dyn State>) {
lua.set("print", hlua::function1(move |val: AnyLuaValue| {
// println!("{:?}", val);
let mut out = String::new();
format_lua(&mut out, &val);
format_lua(&mut out, &val).expect("out of memory");
eprintln!("{}", out);
}))
}
8 changes: 4 additions & 4 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ pub struct Shell<'a> {
}

impl<'a> Shell<'a> {
pub fn new(config: &'a Config, db: Database, blobs: BlobStorage, psl: PslReader, library: Library<'a>, keyring: KeyRing) -> Shell<'a> {
pub fn new(config: &'a Config, db: Database, blobs: BlobStorage, psl: PslReader, library: Library<'a>, keyring: KeyRing) -> Result<Shell<'a>> {
let h = CmdCompleter::default();
let rl = Readline::with(h);
let rl = Readline::with(h)?;

let prompt = Prompt::new(db.name().to_string());

Expand All @@ -197,7 +197,7 @@ impl<'a> Shell<'a> {
rl.reload_module_cache();
rl.reload_keyring_cache();

rl
Ok(rl)
}

#[inline(always)]
Expand Down Expand Up @@ -571,7 +571,7 @@ pub fn init<'a>(args: &Args, config: &'a Config, verbose_init: bool) -> Result<S
}
autoupdate.check_background(config, library.list());

let mut rl = Shell::new(config, db, blobs, psl, library, keyring);
let mut rl = Shell::new(config, db, blobs, psl, library, keyring)?;

ttl::reap_expired(&mut rl)?;

Expand Down
18 changes: 6 additions & 12 deletions src/shell/readline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,29 @@ pub struct Readline<T: rustyline::Helper> {

impl Readline<()> {
#[inline]
pub fn new() -> Readline<()> {
pub fn new() -> Result<Readline<()>> {
Readline::init(None)
}
}

impl Default for Readline<()> {
fn default() -> Self {
Self::new()
}
}

impl<T: rustyline::Helper> Readline<T> {
#[inline]
pub fn with(helper: T) -> Readline<T> {
pub fn with(helper: T) -> Result<Readline<T>> {
Readline::init(Some(helper))
}

fn init(helper: Option<T>) -> Readline<T> {
fn init(helper: Option<T>) -> Result<Readline<T>> {
let rl_config = rustyline::Config::builder()
.completion_type(CompletionType::List)
.edit_mode(EditMode::Emacs)
.build();

let mut rl: Editor<T> = Editor::with_config(rl_config);
let mut rl: Editor<T> = Editor::with_config(rl_config)?;
rl.set_helper(helper);

Readline {
Ok(Readline {
rl,
}
})
}

#[inline]
Expand Down
Loading

0 comments on commit 231d329

Please sign in to comment.