Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Clippy

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

permissions:
contents: read
checks: write
issues: write
pull-requests: write

jobs:
clippy:
name: Clippy Check (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
features: selfupdate,binjuliainstaller,binjulialauncher
- os: windows-latest
features: windowsstore,windowsappinstaller,binjuliainstaller,binjulialauncher
- os: macos-latest
features: selfupdate,binjuliainstaller,binjulialauncher
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: clippy
- name: Run clippy
run: cargo clippy --all-targets --features ${{ matrix.features }} -- -D warnings

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this explain what the user needs to do to pass or just fail?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clippy messages are pretty helpful, so I think the answer is yes

7 changes: 4 additions & 3 deletions src/bin/juliainstaller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ pub fn main() -> Result<()> {
}
}

if failed_paths.len() > 0 {
if !failed_paths.is_empty() {
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");
Expand Down Expand Up @@ -461,7 +461,7 @@ pub fn main() -> Result<()> {
)
})?;

download_extract_sans_parent(&new_juliaup_url.to_string(), &juliaupselfbin, 0)?;
download_extract_sans_parent(new_juliaup_url.as_ref(), &juliaupselfbin, 0)?;

{
let new_selfconfig_data = JuliaupSelfConfig {
Expand All @@ -477,6 +477,7 @@ pub fn main() -> Result<()> {
let mut self_file = std::fs::OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(&self_config_path)
.with_context(|| "Failed to open juliaup config file.")?;

Expand All @@ -489,7 +490,7 @@ pub fn main() -> Result<()> {
})?;

serde_json::to_writer_pretty(&self_file, &new_selfconfig_data)
.with_context(|| format!("Failed to write self configuration file."))?;
.with_context(|| "Failed to write self configuration file.".to_string())?;

self_file
.sync_all()
Expand Down
26 changes: 11 additions & 15 deletions src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ fn run_selfupdate(config_file: &juliaup::config_file::JuliaupReadonlyConfigFile)
let should_run = if let Some(last_selfupdate) = config_file.self_data.last_selfupdate {
let update_time = last_selfupdate + chrono::Duration::minutes(val);

if Utc::now() >= update_time {
true
} else {
false
}
Utc::now() >= update_time
} else {
true
};
Expand Down Expand Up @@ -183,36 +179,36 @@ fn get_julia_path_from_channel(
JuliaupChannelSource::CmdLine => {
if channel_valid {
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else if is_pr_channel(&channel.to_string()) {
} else if is_pr_channel(channel) {
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install pull request channel if available.", channel, channel) }
} else {
UserError { msg: format!("Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
},
JuliaupChannelSource::EnvVar=> {
if channel_valid {
UserError { msg: format!("`{}` from environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else if is_pr_channel(&channel.to_string()) {
} else if is_pr_channel(channel) {
UserError { msg: format!("`{}` from environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install pull request channel if available.", channel, channel) }
} else {
UserError { msg: format!("Invalid Juliaup channel `{}` from environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
},
JuliaupChannelSource::Override=> {
if channel_valid {
UserError { msg: format!("`{}` from directory override is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else if is_pr_channel(&channel.to_string()){
} else if is_pr_channel(channel) {
UserError { msg: format!("`{}` from directory override is not installed. Please run `juliaup add {}` to install pull request channel if available.", channel, channel) }
} else {
UserError { msg: format!("Invalid Juliaup channel `{}` from directory override. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
},
JuliaupChannelSource::Default => UserError {msg: format!("The Juliaup configuration is in an inconsistent state, the currently configured default channel `{}` is not installed.", channel) }
})?;

match channel_info {
JuliaupConfigChannel::LinkedChannel { command, args } => {
return Ok((
Ok((
PathBuf::from(command),
args.as_ref().map_or_else(Vec::new, |v| v.clone()),
))
Expand Down Expand Up @@ -241,7 +237,7 @@ fn get_julia_path_from_channel(
juliaupconfig_path.display()
)
})?;
return Ok((absolute_path.into_path_buf(), Vec::new()));
Ok((absolute_path.into_path_buf(), Vec::new()))
}
JuliaupConfigChannel::DirectDownloadChannel {
path,
Expand Down Expand Up @@ -284,7 +280,7 @@ fn get_julia_path_from_channel(
juliaupconfig_path.display()
)
})?;
return Ok((absolute_path.into_path_buf(), Vec::new()));
Ok((absolute_path.into_path_buf(), Vec::new()))
}
}
}
Expand All @@ -300,7 +296,7 @@ fn get_override_channel(
.iter()
.filter(|i| curr_dir.starts_with(&i.path))
.sorted_by_key(|i| i.path.len())
.last();
.next_back();

match juliaup_override {
Some(val) => Ok(Some(val.channel.clone())),
Expand Down
2 changes: 1 addition & 1 deletion src/command_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn add_non_db(channel: &str, paths: &GlobalPaths) -> Result<()> {
return Ok(());
}

let name = channel_to_name(&channel.to_string())?;
let name = channel_to_name(channel)?;
let config_channel = install_non_db_version(channel, &name, paths)?;

config_file
Expand Down
15 changes: 3 additions & 12 deletions src/command_config_backgroundselfupdate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,12 @@ pub fn run_command_config_backgroundselfupdate(
if value_changed {
eprintln!(
"Property 'backgroundselfupdateinterval' set to '{}'",
match value {
Some(value) => value,
None => 0,
}
value.unwrap_or(0)
);
} else {
eprintln!(
"Property 'backgroundselfupdateinterval' is already set to '{}'",
match value {
Some(value) => value,
None => 0,
}
value.unwrap_or(0)
);
}
}
Expand All @@ -69,10 +63,7 @@ pub fn run_command_config_backgroundselfupdate(
if !quiet {
eprintln!(
"Property 'backgroundselfupdateinterval' set to '{}'",
match config_file.self_data.background_selfupdate_interval {
Some(value) => value,
None => 0,
}
config_file.self_data.background_selfupdate_interval.unwrap_or(0)
);
}
}
Expand Down
15 changes: 3 additions & 12 deletions src/command_config_startupselfupdate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,12 @@ pub fn run_command_config_startupselfupdate(
if value_changed {
eprintln!(
"Property 'startupselfupdateinterval' set to '{}'",
match value {
Some(value) => value,
None => 0,
}
value.unwrap_or(0)
);
} else {
eprintln!(
"Property 'startupselfupdateinterval' is already set to '{}'",
match value {
Some(value) => value,
None => 0,
}
value.unwrap_or(0)
);
}
}
Expand All @@ -59,10 +53,7 @@ pub fn run_command_config_startupselfupdate(
if !quiet {
eprintln!(
"Property 'startupselfupdateinterval' set to '{}'",
match config_file.self_data.startup_selfupdate_interval {
Some(value) => value,
None => 0,
}
config_file.self_data.startup_selfupdate_interval.unwrap_or(0)
);
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/command_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ pub fn run_command_info(paths: &GlobalPaths) -> Result<()> {
if let Ok(versiondb) =
serde_json::from_reader::<BufReader<&std::fs::File>, JuliaupVersionDB>(reader)
{
if let Ok(version) = semver::Version::parse(&versiondb.version) {
Some(version)
} else {
None
}
semver::Version::parse(&versiondb.version).ok()
} else {
None
}
Expand Down
2 changes: 1 addition & 1 deletion src/command_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn run_command_remove(channel: &str, paths: &GlobalPaths) -> Result<()> {
version: _,
} = x
{
let path_to_delete = paths.juliauphome.join(&path);
let path_to_delete = paths.juliauphome.join(path);

let display = path_to_delete.display();

Expand Down
6 changes: 3 additions & 3 deletions src/command_selfuninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ pub fn run_command_selfuninstall(paths: &crate::global_paths::GlobalPaths) -> Re
};

eprint!("Removing startup self update configuration.");
match run_command_config_startupselfupdate(Some(0), true, &paths) {
match run_command_config_startupselfupdate(Some(0), true, paths) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};

eprint!("Removing PATH modifications in startup scripts.");
match run_command_config_modifypath(Some(false), true, &paths) {
match run_command_config_modifypath(Some(false), true, paths) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};

eprint!("Removing symlinks.");
match run_command_config_symlinks(Some(false), true, &paths) {
match run_command_config_symlinks(Some(false), true, paths) {
Ok(_) => eprintln!(" Success."),
Err(_) => eprintln!(" Failed."),
};
Expand Down
4 changes: 2 additions & 2 deletions src/command_selfupdate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
)
})?;

let version = download_juliaup_version(&version_url.to_string())?;
let version = download_juliaup_version(version_url.as_ref())?;

config_file.self_data.last_selfupdate = Some(chrono::Utc::now());

Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
version, juliaup_channel
);

download_extract_sans_parent(&new_juliaup_url.to_string(), &my_own_folder, 0)?;
download_extract_sans_parent(new_juliaup_url.as_ref(), my_own_folder, 0)?;
eprintln!("Updated Juliaup to version {}.", version);
}

Expand Down
4 changes: 2 additions & 2 deletions src/command_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn update_channel(
server_etag: server_etag.clone(),
version: version.clone(),
},
&channel,
channel,
paths,
)?;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn run_command_update(channel: &Option<String>, paths: &GlobalPaths) -> Resu
);
}

update_channel(&mut config_file.data, &channel, &version_db, false, paths)?;
update_channel(&mut config_file.data, channel, &version_db, false, paths)?;
}
};

Expand Down
11 changes: 7 additions & 4 deletions src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub fn get_read_lock(paths: &GlobalPaths) -> Result<FlockLock<File>> {
.read(true)
.write(true)
.create(true)
.truncate(false)
.open(&paths.lockfile)
{
Ok(file) => file,
Expand All @@ -167,7 +168,7 @@ pub fn get_read_lock(paths: &GlobalPaths) -> Result<FlockLock<File>> {
}
};

return Ok(file_lock);
Ok(file_lock)
}

pub fn load_config_db(
Expand Down Expand Up @@ -263,6 +264,7 @@ pub fn load_mut_config_db(paths: &GlobalPaths) -> Result<JuliaupConfigFile> {
.read(true)
.write(true)
.create(true)
.truncate(false)
.open(&paths.lockfile)
{
Ok(file) => file,
Expand All @@ -284,6 +286,7 @@ pub fn load_mut_config_db(paths: &GlobalPaths) -> Result<JuliaupConfigFile> {
.read(true)
.write(true)
.create(true)
.truncate(false)
.open(&paths.juliaupconfig)
.with_context(|| "Failed to open juliaup config file.")?;

Expand Down Expand Up @@ -354,9 +357,9 @@ pub fn load_mut_config_db(paths: &GlobalPaths) -> Result<JuliaupConfigFile> {
lock: file_lock,
data,
#[cfg(feature = "selfupdate")]
self_file: self_file,
self_file,
#[cfg(feature = "selfupdate")]
self_data: self_data,
self_data,
};

Ok(result)
Expand Down Expand Up @@ -396,7 +399,7 @@ pub fn save_config_db(juliaup_config_file: &mut JuliaupConfigFile) -> Result<()>
&juliaup_config_file.self_file,
&juliaup_config_file.self_data,
)
.with_context(|| format!("Failed to write self configuration file."))?;
.with_context(|| "Failed to write self configuration file.".to_string())?;

juliaup_config_file
.self_file
Expand Down
8 changes: 4 additions & 4 deletions src/global_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ fn get_juliaup_home_path() -> Result<PathBuf> {
let val = val.trim();

if val.is_empty() {
return get_default_juliaup_home_path();
get_default_juliaup_home_path()
} else {
let path = PathBuf::from(val);

if !path.is_absolute() {
return Err(anyhow!("The current value of '{}' for the environment variable JULIAUP_DEPOT_PATH is not an absolute path.", val));
Err(anyhow!("The current value of '{}' for the environment variable JULIAUP_DEPOT_PATH is not an absolute path.", val))
} else {
return Ok(PathBuf::from(val).join("juliaup"));
Ok(PathBuf::from(val).join("juliaup"))
}
}
}
Err(_) => return get_default_juliaup_home_path(),
Err(_) => get_default_juliaup_home_path(),
}
}

Expand Down
Loading
Loading