Skip to content

Commit 89edf24

Browse files
authored
Expand usage of secure create_dir function (#131)
Cover all insecure instances of create_dir which could have caused the extension to fail with the function `create_path_if_not_exists`
1 parent d896abe commit 89edf24

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/debugger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Debugger {
210210
language_server_id,
211211
&LanguageServerInstallationStatus::Downloading,
212212
);
213-
fs::create_dir(prefix).map_err(|err| err.to_string())?;
213+
create_path_if_not_exists(prefix)?;
214214

215215
let url = format!(
216216
"https://repo1.maven.org/maven2/com/microsoft/java/{artifact}/{latest_version}/{jar_name}"

src/jdtls.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
env::current_dir,
3-
fs::{create_dir, metadata, read_dir},
3+
fs::{metadata, read_dir},
44
path::{Path, PathBuf},
55
};
66

@@ -18,8 +18,9 @@ use crate::{
1818
config::is_java_autodownload,
1919
jdk::try_to_fetch_and_install_latest_jdk,
2020
util::{
21-
get_curr_dir, get_java_exec_name, get_java_executable, get_java_major_version,
22-
get_latest_versions_from_tag, path_to_string, remove_all_files_except,
21+
create_path_if_not_exists, get_curr_dir, get_java_exec_name, get_java_executable,
22+
get_java_major_version, get_latest_versions_from_tag, path_to_string,
23+
remove_all_files_except,
2324
},
2425
};
2526

@@ -219,7 +220,7 @@ pub fn try_to_fetch_and_install_latest_lombok(
219220
language_server_id,
220221
&LanguageServerInstallationStatus::Downloading,
221222
);
222-
create_dir(prefix).map_err(|err| err.to_string())?;
223+
create_path_if_not_exists(prefix)?;
223224
download_file(
224225
&format!("https://projectlombok.org/downloads/{jar_name}"),
225226
path_to_string(jar_path.clone())?.as_str(),

src/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const JAVA_EXEC_NOT_FOUND_ERROR: &str = "Could not find Java executable in JAVA_
2828
const TAG_RETRIEVAL_ERROR: &str = "Failed to fetch GitHub tags";
2929
const TAG_RESPONSE_ERROR: &str = "Failed to deserialize GitHub tags response";
3030
const TAG_UNEXPECTED_FORMAT_ERROR: &str = "Malformed GitHub tags response";
31+
const PATH_IS_NOT_DIR: &str = "File exists but is not a path";
3132

3233
/// Create a Path if it does not exist
3334
///
@@ -46,7 +47,7 @@ pub fn create_path_if_not_exists<P: AsRef<Path>>(path: P) -> zed::Result<()> {
4647
if metadata.is_dir() {
4748
Ok(())
4849
} else {
49-
Err(format!("File exists but is not a path: {:?}", path_ref))
50+
Err(format!("{PATH_IS_NOT_DIR}: {:?}", path_ref))
5051
}
5152
}
5253
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {

0 commit comments

Comments
 (0)