From c4c6a0a66bda0f55930ba137da2e85244b19c240 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Mon, 19 Aug 2024 11:20:54 -0700 Subject: [PATCH 1/4] Check file permissions before installing --- src/bin/juliainstaller.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/bin/juliainstaller.rs b/src/bin/juliainstaller.rs index 57011b5a..594d5213 100644 --- a/src/bin/juliainstaller.rs +++ b/src/bin/juliainstaller.rs @@ -388,6 +388,41 @@ pub fn main() -> Result<()> { return Ok(()); } + if install_choices.modifypath { + // Now check whether we have the necessary permissions for all the files + // we want to modify. + + let paths = find_shell_scripts_to_be_modified(true)?; + + let failed_paths: Vec = []; + + for cur_path in paths { + let mut file_result = std::fs::OpenOptions::new() + .read(true) + .write(true) + .open(cur_path); + + if file_result.is_err() { + failed_paths.push(cur_path); + } + } + + if failed_paths.len() > 0 { + println!("Juliaup needs to modify a number of existin files on your"); + println!("system, but is unable to edit some of these files. Most likely"); + println!("this is caused by incorrect permissions on these files. The"); + println!("following files could not be edited:"); + for cur_path in failed_paths { + println(" {}", cur_path.display()); + } + println!("You can find more help with this problem at"); + println!(" https://github.com/JuliaLang/juliaup/wiki/Permission-problems-during-setup"); + println!(); + + return Ok(()); + } + } + let juliaupselfbin = install_choices.install_location.join("bin"); trace!("Set juliaupselfbin to `{:?}`", juliaupselfbin); From 8dcb6cd6f9a6f7289b883c6392d5e6b1b6615f1d Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Mon, 19 Aug 2024 11:25:10 -0700 Subject: [PATCH 2/4] Only check existing file permissions --- src/bin/juliainstaller.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/juliainstaller.rs b/src/bin/juliainstaller.rs index 594d5213..1f7a2c4e 100644 --- a/src/bin/juliainstaller.rs +++ b/src/bin/juliainstaller.rs @@ -392,7 +392,7 @@ pub fn main() -> Result<()> { // Now check whether we have the necessary permissions for all the files // we want to modify. - let paths = find_shell_scripts_to_be_modified(true)?; + let paths = find_shell_scripts_to_be_modified(false)?; let failed_paths: Vec = []; @@ -416,7 +416,9 @@ pub fn main() -> Result<()> { println(" {}", cur_path.display()); } println!("You can find more help with this problem at"); - println!(" https://github.com/JuliaLang/juliaup/wiki/Permission-problems-during-setup"); + println!( + " https://github.com/JuliaLang/juliaup/wiki/Permission-problems-during-setup" + ); println!(); return Ok(()); From b4291345e5ffa1bb7f78add1a30ac1d56b926027 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Mon, 19 Aug 2024 11:26:12 -0700 Subject: [PATCH 3/4] Fix typo --- src/bin/juliainstaller.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/juliainstaller.rs b/src/bin/juliainstaller.rs index 1f7a2c4e..df56e8ef 100644 --- a/src/bin/juliainstaller.rs +++ b/src/bin/juliainstaller.rs @@ -408,7 +408,7 @@ pub fn main() -> Result<()> { } if failed_paths.len() > 0 { - println!("Juliaup needs to modify a number of existin files on your"); + println!("Juliaup needs to modify a number of existing files on your"); println!("system, but is unable to edit some of these files. Most likely"); println!("this is caused by incorrect permissions on these files. The"); println!("following files could not be edited:"); From ca4c600128492be11012159c44a8dcd64255b426 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Mon, 19 Aug 2024 11:48:22 -0700 Subject: [PATCH 4/4] Fix bugs --- src/bin/juliainstaller.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bin/juliainstaller.rs b/src/bin/juliainstaller.rs index df56e8ef..16d3a68c 100644 --- a/src/bin/juliainstaller.rs +++ b/src/bin/juliainstaller.rs @@ -394,16 +394,16 @@ pub fn main() -> Result<()> { let paths = find_shell_scripts_to_be_modified(false)?; - let failed_paths: Vec = []; + let mut failed_paths: Vec = Vec::::new(); for cur_path in paths { - let mut file_result = std::fs::OpenOptions::new() + let file_result = std::fs::OpenOptions::new() .read(true) .write(true) - .open(cur_path); + .open(&cur_path); if file_result.is_err() { - failed_paths.push(cur_path); + failed_paths.push(cur_path.clone()); } } @@ -413,7 +413,7 @@ pub fn main() -> Result<()> { println!("this is caused by incorrect permissions on these files. The"); println!("following files could not be edited:"); for cur_path in failed_paths { - println(" {}", cur_path.display()); + println!(" {}", cur_path.display()); } println!("You can find more help with this problem at"); println!(