Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/cli/self_update_stub.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
use std::collections::BTreeMap;
use std::fs;
use std::path::PathBuf;

use crate::env;

pub struct SelfUpdate {}

impl SelfUpdate {
pub fn is_available() -> bool {
false
}
}

#[derive(Debug, Default, serde::Deserialize)]
struct InstructionsToml {
message: Option<String>,
#[serde(flatten)]
commands: BTreeMap<String, String>,
}

fn read_instructions_file(path: &PathBuf) -> Option<String> {
let body = fs::read_to_string(path).ok()?;
let parsed: InstructionsToml = toml::from_str(&body).ok()?;
if let Some(msg) = parsed.message {
return Some(msg);
}
if let Some((_k, v)) = parsed.commands.into_iter().next() {
return Some(v);
}
None
}

pub fn upgrade_instructions_text() -> Option<String> {
if let Some(path) = &*env::MISE_SELF_UPDATE_INSTRUCTIONS {
if let Some(msg) = read_instructions_file(path) {
return Some(msg);
}
}
None
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Stub Function Performs Unnecessary I/O Operations

The upgrade_instructions_text() function in the self_update_stub module reads and parses a TOML file. As a stub for a disabled feature, it's expected to be a no-op and return None directly. This current behavior introduces unnecessary file I/O and TOML parsing dependencies, potentially leading to runtime errors when the self_update feature is not enabled.

Fix in Cursor Fix in Web


pub fn append_self_update_instructions(mut message: String) -> String {
if let Some(instructions) = upgrade_instructions_text() {
message.push('\n');
message.push_str(&instructions);
}
message
}
Loading