Skip to content

Commit

Permalink
change: now the same for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
MordechaiHadad committed Jul 23, 2024
1 parent 909d6e3 commit c325de6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/handlers/install_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async fn handle_rollback(config: &Config) -> Result<()> {
.collect();

info!("Creating rollback: nightly-{id}");
filesystem::copy_dir("nightly", format!("nightly-{id}")).await?;
filesystem::copy_dir_async("nightly", format!("nightly-{id}")).await?;

json_struct.tag_name += &format!("-{id}");

Expand Down
27 changes: 25 additions & 2 deletions src/helpers/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub async fn remove_dir(directory: &str) -> Result<()> {
/// copy_dir(from, to).await;
/// ```
#[async_recursion(?Send)]
pub async fn copy_dir(
pub async fn copy_dir_async(
from: impl AsRef<Path> + 'static,
to: impl AsRef<Path> + 'static,
) -> Result<()> {
Expand All @@ -105,7 +105,7 @@ pub async fn copy_dir(

if path.is_dir() {
let new_dest = destination.join(path.file_name().unwrap());
copy_dir(path, new_dest).await?;
copy_dir_async(path, new_dest).await?;
} else {
let new_dest = destination.join(path.file_name().unwrap());
fs::copy(path, new_dest).await?;
Expand All @@ -114,3 +114,26 @@ pub async fn copy_dir(

Ok(())
}

pub fn copy_dir(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {

Check failure on line 118 in src/helpers/filesystem.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

function `copy_dir` is never used

Check warning on line 118 in src/helpers/filesystem.rs

View workflow job for this annotation

GitHub Actions / check (macos-latest)

function `copy_dir` is never used

Check warning on line 118 in src/helpers/filesystem.rs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

function `copy_dir` is never used

Check warning on line 118 in src/helpers/filesystem.rs

View workflow job for this annotation

GitHub Actions / check (windows-latest)

function `copy_dir` is never used

Check warning on line 118 in src/helpers/filesystem.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

function `copy_dir` is never used
let original_path = from.as_ref().to_owned();
let destination = to.as_ref().to_owned();

std::fs::create_dir(&destination)?;

let mut entries = std::fs::read_dir(original_path)?;

while let Some(entry) = entries.next() {

Check failure on line 126 in src/helpers/filesystem.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest)

this loop could be written as a `for` loop

Check failure on line 126 in src/helpers/filesystem.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest)

this loop could be written as a `for` loop
let path = entry?.path();

if path.is_dir() {
let new_dest = destination.join(path.file_name().unwrap());
copy_dir(path, new_dest)?;
} else {
let new_dest = destination.join(path.file_name().unwrap());
std::fs::copy(path, new_dest)?;
}
}

Ok(())
}
20 changes: 7 additions & 13 deletions src/helpers/unarchive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ pub async fn start(file: LocalVersion) -> Result<()> {
/// ```
#[cfg(target_os = "linux")]
fn expand(downloaded_file: LocalVersion) -> Result<()> {
use crate::helpers::filesystem::copy_dir;

use super::sync;
use std::env::set_current_dir;
use std::fs::{remove_file, rename};
use std::fs::remove_dir_all;
use std::os::unix::fs::PermissionsExt;
use std::process::Command;

Expand All @@ -126,18 +127,11 @@ fn expand(downloaded_file: LocalVersion) -> Result<()> {

sync::handle_subprocess(Command::new(file).arg("--appimage-extract"))?;

rename("squashfs-root", &downloaded_file.file_name)?;

set_current_dir(downloaded_file.file_name)?;

for x in ["AppRun", "nvim.desktop", "nvim.png", ".DirIcon"] {
remove_file(x)?;
}

rename("usr", "nvim-linux64")?;
let src_root = "squashfs-root";
let dest = downloaded_file.file_name;

let parent_dir = std::env::current_dir()?.parent().unwrap().to_path_buf();
std::env::set_current_dir(parent_dir)?;
copy_dir(Path::new(src_root).join("usr"), Path::new(&dest))?;
remove_dir_all(src_root)?;

Ok(())
}
Expand Down

0 comments on commit c325de6

Please sign in to comment.