Hunting down a bug
This commit is contained in:
parent
d7681e1dcd
commit
1ec9ee7cc7
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2322,7 +2322,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shibe-bot"
|
name = "shibe-bot"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
|
@ -3,7 +3,7 @@ name = "shibe-bot"
|
|||||||
description = "A Discord bot written in Rust, using Poise."
|
description = "A Discord bot written in Rust, using Poise."
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
|
@ -42,9 +42,12 @@ pub async fn version(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the bot remotely (Requires updater systemd service)
|
/// Update the bot remotely (requires Github CI)
|
||||||
#[poise::command(slash_command, owners_only, hide_in_help)]
|
#[poise::command(slash_command, owners_only, hide_in_help)]
|
||||||
pub async fn update(ctx: Context<'_>, override_check: bool) -> Result<(), Error> {
|
pub async fn update(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "Whether to skip the update check"] override_check: bool,
|
||||||
|
) -> Result<(), Error> {
|
||||||
// Check if the current commit hash is different from HEAD
|
// Check if the current commit hash is different from HEAD
|
||||||
let head: octocrab::models::repos::Ref = octocrab::instance()
|
let head: octocrab::models::repos::Ref = octocrab::instance()
|
||||||
.get(
|
.get(
|
||||||
@ -56,7 +59,8 @@ pub async fn update(ctx: Context<'_>, override_check: bool) -> Result<(), Error>
|
|||||||
if sha == env!("GIT_COMMIT_ID") {
|
if sha == env!("GIT_COMMIT_ID") {
|
||||||
if override_check {
|
if override_check {
|
||||||
info!("Update unnecessary, but check overridden.");
|
info!("Update unnecessary, but check overridden.");
|
||||||
ctx.say("Update unecessary, but check overridden. Updating.").await?;
|
ctx.say("Update unecessary, but check overridden. Updating.")
|
||||||
|
.await?;
|
||||||
let Err(what) = self_update();
|
let Err(what) = self_update();
|
||||||
error!("Update failed: {}", what);
|
error!("Update failed: {}", what);
|
||||||
ctx.say(format!("Error occurred while updating: {}", what))
|
ctx.say(format!("Error occurred while updating: {}", what))
|
||||||
@ -73,7 +77,8 @@ pub async fn update(ctx: Context<'_>, override_check: bool) -> Result<(), Error>
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.say("Update failed: Object field in response is not a Commit.").await?;
|
ctx.say("Update failed: Object field in response is not a Commit.")
|
||||||
|
.await?;
|
||||||
error!("Checking for updates failed: Response field incorrect type");
|
error!("Checking for updates failed: Response field incorrect type");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -126,7 +131,6 @@ fn self_update() -> Result<Infallible, Error> {
|
|||||||
dest.write_all(&content)?;
|
dest.write_all(&content)?;
|
||||||
trace!("Downloaded latest build artifact successfully");
|
trace!("Downloaded latest build artifact successfully");
|
||||||
|
|
||||||
|
|
||||||
let mut archive = zip::ZipArchive::new(dest)?;
|
let mut archive = zip::ZipArchive::new(dest)?;
|
||||||
trace!("Created zip archive reader");
|
trace!("Created zip archive reader");
|
||||||
let mut zipped_bin = archive.by_index(0)?;
|
let mut zipped_bin = archive.by_index(0)?;
|
||||||
@ -137,12 +141,26 @@ fn self_update() -> Result<Infallible, Error> {
|
|||||||
std::io::copy(&mut zipped_bin, &mut new_bin)?;
|
std::io::copy(&mut zipped_bin, &mut new_bin)?;
|
||||||
trace!("Extracted binary successfully");
|
trace!("Extracted binary successfully");
|
||||||
|
|
||||||
|
let new_command_path = std::env::current_exe()?;
|
||||||
|
|
||||||
|
trace!("Testing file prior to replace");
|
||||||
|
{
|
||||||
|
let _ = std::fs::File::open(&new_command_path)?;
|
||||||
|
}
|
||||||
|
|
||||||
self_replace::self_replace(&new_bin_path)?;
|
self_replace::self_replace(&new_bin_path)?;
|
||||||
trace!("Replaced self with new binary successfully");
|
trace!("Replaced self with new binary successfully");
|
||||||
|
|
||||||
|
trace!("Testing file after replace");
|
||||||
|
{
|
||||||
|
let _ = std::fs::File::open(&new_command_path)?;
|
||||||
|
}
|
||||||
|
|
||||||
let new_command_args: Vec<_> = std::env::args_os().skip(1).collect();
|
let new_command_args: Vec<_> = std::env::args_os().skip(1).collect();
|
||||||
let new_command_path = std::env::current_exe()?;
|
trace!(
|
||||||
trace!("Got current executable path successfully: {}", new_command_path.display());
|
"Got current executable path successfully: {}",
|
||||||
|
new_command_path.display()
|
||||||
|
);
|
||||||
|
|
||||||
Err(Box::new(
|
Err(Box::new(
|
||||||
std::process::Command::new(new_command_path)
|
std::process::Command::new(new_command_path)
|
||||||
@ -153,17 +171,16 @@ fn self_update() -> Result<Infallible, Error> {
|
|||||||
|
|
||||||
mod test {
|
mod test {
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
use std::convert::Infallible;
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
#[cfg(test)]
|
||||||
|
use std::convert::Infallible;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_self_update() -> Result<Infallible, Error> {
|
fn test_self_update() -> Result<Infallible, Error> {
|
||||||
use pretty_env_logger;
|
|
||||||
use crate::command::devel::self_update;
|
use crate::command::devel::self_update;
|
||||||
|
use pretty_env_logger;
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
self_update()
|
self_update()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,10 @@ async fn main() {
|
|||||||
// Initialize logging
|
// Initialize logging
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
info!("Initialized logger successfully");
|
info!("Initialized logger successfully");
|
||||||
|
info!(
|
||||||
|
"Current executable path: {}",
|
||||||
|
std::env::current_exe().unwrap()
|
||||||
|
);
|
||||||
// Get secure env vars from .env file
|
// Get secure env vars from .env file
|
||||||
match dotenv() {
|
match dotenv() {
|
||||||
Ok(_) => info!("Loaded env vars from .env successfully"),
|
Ok(_) => info!("Loaded env vars from .env successfully"),
|
||||||
|
Loading…
Reference in New Issue
Block a user