mirror of
https://github.com/pesde-pkg/pesde.git
synced 2024-12-12 11:00:36 +00:00
fix: update binary when upgrading
This commit is contained in:
parent
37cc86f028
commit
97b6a69688
5 changed files with 32 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::cli::{files::make_executable, home_dir, IsUpToDate};
|
||||
use crate::cli::{bin_dir, files::make_executable, home_dir, IsUpToDate};
|
||||
use anyhow::Context;
|
||||
use clap::Args;
|
||||
use indicatif::MultiProgress;
|
||||
|
@ -167,7 +167,7 @@ impl InstallCommand {
|
|||
.apply_patches(&downloaded_graph)
|
||||
.context("failed to apply patches")?;
|
||||
|
||||
let bin_folder = home_dir()?.join("bin");
|
||||
let bin_folder = bin_dir()?;
|
||||
|
||||
for versions in downloaded_graph.values() {
|
||||
for node in versions.values() {
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use crate::cli::{files::make_executable, home_dir, scripts::update_scripts_folder, HOME_DIR};
|
||||
use crate::cli::{
|
||||
bin_dir, files::make_executable, home_dir, scripts::update_scripts_folder,
|
||||
version::update_bin_exe, HOME_DIR,
|
||||
};
|
||||
use anyhow::Context;
|
||||
use clap::Args;
|
||||
use colored::Colorize;
|
||||
|
@ -16,8 +19,7 @@ impl SelfInstallCommand {
|
|||
pub fn run(self, project: Project) -> anyhow::Result<()> {
|
||||
update_scripts_folder(&project)?;
|
||||
|
||||
let bin_dir = home_dir()?.join("bin");
|
||||
create_dir_all(&bin_dir).context("failed to create bin folder")?;
|
||||
let bin_dir = bin_dir()?;
|
||||
|
||||
#[cfg(windows)]
|
||||
if !self.skip_add_to_path {
|
||||
|
@ -74,14 +76,7 @@ and then restart your shell.
|
|||
);
|
||||
}
|
||||
|
||||
let copy_to = bin_dir
|
||||
.join(env!("CARGO_BIN_NAME"))
|
||||
.with_extension(std::env::consts::EXE_EXTENSION);
|
||||
|
||||
std::fs::copy(std::env::current_exe()?, ©_to)
|
||||
.context("failed to copy executable to bin folder")?;
|
||||
|
||||
make_executable(©_to)?;
|
||||
update_bin_exe()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use crate::cli::{config::read_config, version::get_or_download_version};
|
||||
use crate::cli::{
|
||||
config::read_config,
|
||||
version::{get_or_download_version, update_bin_exe},
|
||||
};
|
||||
use clap::Args;
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
|
@ -13,6 +16,7 @@ impl SelfUpgradeCommand {
|
|||
let config = read_config()?;
|
||||
|
||||
get_or_download_version(&reqwest, &config.last_checked_updates.unwrap().1)?;
|
||||
update_bin_exe()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use anyhow::Context;
|
|||
use pesde::{
|
||||
lockfile::DownloadedGraph, names::PackageNames, source::version_id::VersionId, Project,
|
||||
};
|
||||
use std::{collections::HashSet, str::FromStr};
|
||||
use std::{collections::HashSet, fs::create_dir_all, str::FromStr};
|
||||
|
||||
pub const HOME_DIR: &str = concat!(".", env!("CARGO_PKG_NAME"));
|
||||
|
||||
|
@ -20,6 +20,12 @@ pub fn home_dir() -> anyhow::Result<std::path::PathBuf> {
|
|||
.join(HOME_DIR))
|
||||
}
|
||||
|
||||
pub fn bin_dir() -> anyhow::Result<std::path::PathBuf> {
|
||||
let bin_dir = home_dir()?.join("bin");
|
||||
create_dir_all(&bin_dir).context("failed to create bin folder")?;
|
||||
Ok(bin_dir)
|
||||
}
|
||||
|
||||
pub trait IsUpToDate {
|
||||
fn is_up_to_date(&self, strict: bool) -> anyhow::Result<bool>;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use semver::Version;
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::cli::{
|
||||
bin_dir,
|
||||
config::{read_config, write_config, CliConfig},
|
||||
files::make_executable,
|
||||
home_dir,
|
||||
|
@ -206,3 +207,14 @@ pub fn max_installed_version() -> anyhow::Result<Version> {
|
|||
|
||||
Ok(max_version)
|
||||
}
|
||||
|
||||
pub fn update_bin_exe() -> anyhow::Result<()> {
|
||||
let copy_to = bin_dir()?
|
||||
.join(env!("CARGO_BIN_NAME"))
|
||||
.with_extension(std::env::consts::EXE_EXTENSION);
|
||||
|
||||
std::fs::copy(std::env::current_exe()?, ©_to)
|
||||
.context("failed to copy executable to bin folder")?;
|
||||
|
||||
make_executable(©_to)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue