Skip to content

Commit 6501149

Browse files
Merge pull request #283 from MordechaiHadad/change/linux-tarball
Rollback to using tar.gz instead of appimages for neovim binaries
2 parents 644bf35 + 5e9c2c2 commit 6501149

File tree

5 files changed

+8
-138
lines changed

5 files changed

+8
-138
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ optional = false
8484
version = "0.28.0"
8585
features = ["signal"]
8686

87-
[target.'cfg(target_os = "macos")'.dependencies]
87+
[target.'cfg(unix)'.dependencies]
8888
flate2 = "1.0.26"
8989
tar = "0.4"
9090

src/helpers/filesystem.rs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -114,53 +114,3 @@ pub async fn copy_dir_async(
114114

115115
Ok(())
116116
}
117-
118-
/// Copies a directory from one location to another.
119-
///
120-
/// This function takes two arguments: the source directory and the destination directory. Both arguments are implemented as references to `Path` and are static.
121-
/// It first creates the destination directory, then reads the entries of the source directory.
122-
/// For each entry in the source directory, it checks if the entry is a directory or a file.
123-
/// If the entry is a directory, it recursively calls `copy_dir` to copy the directory to the destination.
124-
/// If the entry is a file, it copies the file to the destination.
125-
///
126-
/// # Arguments
127-
///
128-
/// * `from` - A reference to a `Path` representing the source directory.
129-
/// * `to` - A reference to a `Path` representing the destination directory.
130-
///
131-
/// # Returns
132-
///
133-
/// This function returns a `Result` that indicates whether the operation was successful.
134-
/// If the operation was successful, the function returns `Ok(())`.
135-
/// If the operation failed, the function returns `Err` with a description of the error.
136-
///
137-
/// # Example
138-
///
139-
/// ```rust
140-
/// let from = Path::new("/path/to/source");
141-
/// let to = Path::new("/path/to/destination");
142-
/// copy_dir(from, to).await;
143-
/// ```
144-
#[cfg(target_os = "linux")]
145-
pub fn copy_dir(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
146-
let original_path = from.as_ref().to_owned();
147-
let destination = to.as_ref().to_owned();
148-
149-
std::fs::create_dir(&destination)?;
150-
151-
let entries = std::fs::read_dir(original_path)?;
152-
153-
for entry in entries {
154-
let path = entry?.path();
155-
156-
if path.is_dir() {
157-
let new_dest = destination.join(path.file_name().unwrap());
158-
copy_dir(path, new_dest)?;
159-
} else {
160-
let new_dest = destination.join(path.file_name().unwrap());
161-
std::fs::copy(path, new_dest)?;
162-
}
163-
}
164-
165-
Ok(())
166-
}

src/helpers/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ pub mod checksum;
22
pub mod directories;
33
pub mod filesystem;
44
pub mod processes;
5-
pub mod sync;
65
pub mod unarchive;
76
pub mod version;
87
use semver::Version;
@@ -11,8 +10,7 @@ use semver::Version;
1110
///
1211
/// This function checks the target operating system using the `cfg!` macro and returns a string that corresponds to the appropriate file type for the Neovim binary download.
1312
/// For Windows, it returns "zip".
14-
/// For macOS, it returns "tar.gz".
15-
/// For other operating systems, it returns "appimage".
13+
/// For unix, it returns "tar.gz".
1614
///
1715
/// # Returns
1816
///
@@ -26,10 +24,8 @@ use semver::Version;
2624
pub fn get_file_type() -> &'static str {
2725
if cfg!(target_family = "windows") {
2826
"zip"
29-
} else if cfg!(target_os = "macos") {
30-
"tar.gz"
3127
} else {
32-
"appimage"
28+
"tar.gz"
3329
}
3430
}
3531

src/helpers/unarchive.rs

Lines changed: 5 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use super::version::types::LocalVersion;
3636
/// ```rust
3737
/// let downloaded_file = LocalVersion {
3838
/// file_name: "nvim-linux",
39-
/// file_format: "AppImage",
39+
/// file_format: "tar.gz",
4040
/// semver: semver::Version::parse("0.5.0").unwrap(),
4141
/// path: "/path/to/downloaded/file",
4242
/// };
@@ -60,82 +60,6 @@ pub async fn start(file: LocalVersion) -> Result<()> {
6060
.await?;
6161
Ok(())
6262
}
63-
64-
/// Expands a downloaded file on Linux.
65-
///
66-
/// This function is specific to Linux due to the use of certain features like `os::unix::fs::PermissionsExt`.
67-
/// It takes a `LocalVersion` struct which contains information about the downloaded file, such as its name and format.
68-
/// The function then checks if a directory with the same name as the downloaded file exists, and if so, removes it.
69-
/// It then sets the permissions of the downloaded file to `0o551` and extracts its contents using the `--appimage-extract` command.
70-
/// After extraction, the function renames the `squashfs-root` directory to the name of the downloaded file and changes the current directory to the renamed directory.
71-
/// It then removes certain files and renames the `usr` directory to `nvim-linux64`.
72-
/// Finally, it changes the current directory back to the parent directory.
73-
///
74-
/// # Arguments
75-
///
76-
/// * `downloaded_file` - A `LocalVersion` struct representing the downloaded file.
77-
///
78-
/// # Returns
79-
///
80-
/// This function returns a `Result` that indicates whether the operation was successful.
81-
/// If the operation was successful, the function returns `Ok(())`.
82-
/// If the operation failed, the function returns `Err` with a description of the error.
83-
///
84-
/// # Errors
85-
///
86-
/// This function will return an error if:
87-
///
88-
/// * A directory with the same name as the downloaded file could not be removed.
89-
/// * The permissions of the downloaded file could not be set.
90-
/// * The downloaded file could not be extracted.
91-
/// * The `squashfs-root` directory could not be renamed.
92-
/// * The current directory could not be changed.
93-
/// * Certain files could not be removed.
94-
/// * The `usr` directory could not be renamed.
95-
///
96-
/// # Example
97-
///
98-
/// ```rust
99-
/// let downloaded_file = LocalVersion {
100-
/// file_name: "nvim-linux",
101-
/// file_format: "AppImage",
102-
/// semver: semver::Version::parse("0.5.0").unwrap(),
103-
/// path: "/path/to/downloaded/file",
104-
/// };
105-
/// expand(downloaded_file);
106-
/// ```
107-
#[cfg(target_os = "linux")]
108-
fn expand(downloaded_file: LocalVersion) -> Result<()> {
109-
use crate::helpers::filesystem::copy_dir;
110-
111-
use super::sync;
112-
use std::fs::remove_dir_all;
113-
use std::os::unix::fs::PermissionsExt;
114-
use std::process::Command;
115-
116-
if fs::metadata(&downloaded_file.file_name).is_ok() {
117-
fs::remove_dir_all(&downloaded_file.file_name)?;
118-
}
119-
120-
let file = &format!(
121-
"./{}.{}",
122-
downloaded_file.file_name, downloaded_file.file_format
123-
);
124-
let mut perms = fs::metadata(file)?.permissions();
125-
perms.set_mode(0o551);
126-
fs::set_permissions(file, perms)?;
127-
128-
sync::handle_subprocess(Command::new(file).arg("--appimage-extract"))?;
129-
130-
let src_root = "squashfs-root";
131-
let dest = downloaded_file.file_name;
132-
133-
copy_dir(Path::new(src_root).join("usr"), Path::new(&dest))?;
134-
remove_dir_all(src_root)?;
135-
136-
Ok(())
137-
}
138-
13963
/// Expands a downloaded file on Windows.
14064
///
14165
/// This function is specific to Windows due to the use of certain features like `zip::ZipArchive`.
@@ -236,9 +160,9 @@ fn expand(downloaded_file: LocalVersion) -> Result<()> {
236160
Ok(())
237161
}
238162

239-
/// Expands a downloaded file on macOS.
163+
/// Expands a downloaded file on Unix systems (macOS and Linux).
240164
///
241-
/// This function is specific to macOS due to the use of certain features like `os::unix::fs::PermissionsExt`.
165+
/// This function is specific to Unix systems due to the use of certain features like `os::unix::fs::PermissionsExt`.
242166
/// It takes a `LocalVersion` struct which contains information about the downloaded file, such as its name and format.
243167
/// The function then opens the file, decompresses it using `GzDecoder`, and extracts its contents using `tar::Archive`.
244168
/// During the extraction process, a progress bar is displayed to the user.
@@ -268,14 +192,14 @@ fn expand(downloaded_file: LocalVersion) -> Result<()> {
268192
///
269193
/// ```rust
270194
/// let downloaded_file = LocalVersion {
271-
/// file_name: "nvim-macos",
195+
/// file_name: "nvim-linux",
272196
/// file_format: "tar.gz",
273197
/// semver: semver::Version::parse("0.5.0").unwrap(),
274198
/// path: "/path/to/downloaded/file",
275199
/// };
276200
/// expand(downloaded_file);
277201
/// ```
278-
#[cfg(target_os = "macos")] // I don't know if its worth making both expand functions into one function, but the API difference will cause so much if statements
202+
#[cfg(unix)]
279203
fn expand(downloaded_file: LocalVersion) -> Result<()> {
280204
use flate2::read::GzDecoder;
281205
use indicatif::{ProgressBar, ProgressStyle};

0 commit comments

Comments
 (0)