Skip to content

Commit 07cf984

Browse files
committed
chore: fix formatting, clippy warnings and ensure tests pass
1 parent af0ef46 commit 07cf984

4 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/commands/install.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ pub async fn execute_install(version: &str) -> Result<()> {
7373
let v = crate::fs::resolve_local_version(&resolved_version)?;
7474
let bin_dir = crate::fs::get_version_bin_dir(&v)?;
7575
let s = crate::shell::detect_shell();
76-
let export_str1 =
77-
s.set_env_var(MULTISHELL_PATH_VAR, &bin_dir.to_string_lossy());
76+
let export_str1 = s.set_env_var(MULTISHELL_PATH_VAR, &bin_dir.to_string_lossy());
7877
let export_str2 = s.path(&bin_dir);
7978

8079
let env_file = crate::fs::get_env_update_path(None)?;
@@ -88,7 +87,7 @@ pub async fn execute_install(version: &str) -> Result<()> {
8887
let mut writer = std::io::BufWriter::new(&file);
8988
writeln!(writer, "{}\n{}", export_str1, export_str2)?;
9089
writer.flush()?;
91-
file.unlock()?;
90+
fs4::fs_std::FileExt::unlock(&file)?;
9291

9392
unsafe {
9493
std::env::set_var(MULTISHELL_PATH_VAR, &bin_dir);

src/commands/use_cmd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl Use {
127127
writeln!(writer, "{}", export_str1)?;
128128
writeln!(writer, "{}", export_str2)?;
129129
writer.flush()?;
130-
file.unlock()?;
130+
fs4::fs_std::FileExt::unlock(&file)?;
131131

132132
// Also update the current Rust binary's environment so spawned subs (or interactive loop) see it
133133
unsafe {

src/network.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,19 @@ pub async fn get_available_versions() -> Result<Vec<String>> {
4040
// 1. Try to load from valid cache
4141
if cache_path.exists() {
4242
if let Ok(file) = File::open(&cache_path) {
43-
file.lock_shared().ok();
43+
fs4::fs_std::FileExt::lock_shared(&file).ok();
4444
let mut contents = String::new();
4545
let mut f = &file;
4646
let read_res = f.read_to_string(&mut contents);
47-
file.unlock().ok();
47+
fs4::fs_std::FileExt::unlock(&file).ok();
4848

4949
if read_res.is_ok() {
5050
if let Ok(metadata) = std::fs::metadata(&cache_path) {
5151
if let Ok(modified) = metadata.modified() {
5252
if let Ok(elapsed) = modified.elapsed() {
5353
if elapsed < CACHE_DURATION {
54-
if let Ok(versions) = serde_json::from_str::<Vec<String>>(&contents) {
54+
if let Ok(versions) = serde_json::from_str::<Vec<String>>(&contents)
55+
{
5556
return Ok(versions);
5657
}
5758
}
@@ -95,10 +96,7 @@ pub async fn get_available_versions() -> Result<Vec<String>> {
9596

9697
let mut versions = Vec::new();
9798
for file in res {
98-
if !file.is_dir
99-
&& file.name.starts_with("php-")
100-
&& file.name.ends_with(&suffix)
101-
{
99+
if !file.is_dir && file.name.starts_with("php-") && file.name.ends_with(&suffix) {
102100
if let Some(version) = file
103101
.name
104102
.strip_prefix("php-")
@@ -116,6 +114,7 @@ pub async fn get_available_versions() -> Result<Vec<String>> {
116114
std::fs::create_dir_all(&pvm_dir).ok();
117115
if let Ok(file) = std::fs::OpenOptions::new()
118116
.create(true)
117+
.truncate(false)
119118
.read(true)
120119
.write(true)
121120
.open(&cache_path)
@@ -125,7 +124,7 @@ pub async fn get_available_versions() -> Result<Vec<String>> {
125124
let mut writer = std::io::BufWriter::new(&file);
126125
writer.write_all(json.as_bytes()).ok();
127126
writer.flush().ok();
128-
file.unlock().ok();
127+
fs4::fs_std::FileExt::unlock(&file).ok();
129128
}
130129
}
131130

src/update.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub async fn check_for_updates(target_version: &str) -> Result<Option<String>> {
1717
// Acquire lock and check if 24 hours have passed
1818
let mut file = std::fs::OpenOptions::new()
1919
.create(true)
20+
.truncate(false)
2021
.read(true)
2122
.write(true)
2223
.open(&guard_file)?;
@@ -30,7 +31,7 @@ pub async fn check_for_updates(target_version: &str) -> Result<Option<String>> {
3031
if !contents.is_empty() {
3132
if let Ok(last_check) = contents.trim().parse::<u64>() {
3233
if now - last_check < 86400 {
33-
file.unlock().ok();
34+
fs4::fs_std::FileExt::unlock(&file).ok();
3435
return Ok(None);
3536
}
3637
}
@@ -42,7 +43,7 @@ pub async fn check_for_updates(target_version: &str) -> Result<Option<String>> {
4243
let mut writer = std::io::BufWriter::new(&file);
4344
writeln!(writer, "{}", now).ok();
4445
writer.flush().ok();
45-
file.unlock().ok();
46+
fs4::fs_std::FileExt::unlock(&file).ok();
4647

4748
if target_version == "system" {
4849
return Ok(None);

0 commit comments

Comments
 (0)