Skip to content

Commit 2f3fb25

Browse files
authored
Download nightly build based on checksum (#44)
Should close #42 Instead of downloading the nightly build to always the same folder `~/Library/Application\ Support/Zed/extensions/work/elixir/expert-nightly` which doesn't overwrite the existing installation since the `-nightly` suffix never changes, I use the checksum from the `expert_checksums.txt` file as a folder name - and therefore as a "version" which gets overwritten the next time a nightly release is pushed. I closed the previous PR #43 to move this to a feature branch
1 parent 40f5ddf commit 2f3fb25

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/language_servers/expert.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,44 @@ impl Expert {
9999
.find(|asset| asset.name == asset_name)
100100
.ok_or_else(|| format!("no asset found matching {:?}", asset_name))?;
101101

102-
let version_dir = format!("{}-{}", Self::LANGUAGE_SERVER_ID, release.version);
103-
fs::create_dir_all(&version_dir).map_err(|e| format!("failed to create directory: {e}"))?;
102+
let checksum_asset = release
103+
.assets
104+
.iter()
105+
.find(|asset| asset.name == "expert_checksums.txt")
106+
.ok_or_else(|| format!("no checksums file found in release"))?;
107+
108+
let checksums_dir = format!("{}-checksums", Self::LANGUAGE_SERVER_ID);
109+
fs::create_dir_all(&checksums_dir)
110+
.map_err(|e| format!("failed to create directory: {e}"))?;
111+
112+
let checksums_path = format!("{checksums_dir}/expert_checksums.txt");
113+
114+
zed::download_file(
115+
&checksum_asset.download_url,
116+
&checksums_path,
117+
zed::DownloadedFileType::Uncompressed,
118+
)
119+
.map_err(|e| format!("failed to download checksums file: {e}"))?;
120+
121+
let checksums_content = fs::read_to_string(&checksums_path)
122+
.map_err(|e| format!("failed to read checksums file: {e}"))?;
123+
124+
fs::remove_dir_all(&checksums_dir)
125+
.map_err(|e| format!("failed to remove checksums directory: {e}"))?;
126+
127+
let truncated_checksum = checksums_content
128+
.lines()
129+
.find(|line| line.ends_with(&asset_name))
130+
.and_then(|line| line.split_whitespace().next())
131+
.ok_or_else(|| format!("checksum not found for {}", asset_name))?
132+
.chars()
133+
.take(8)
134+
.collect::<String>();
135+
136+
let expert_dir = format!("{}-{}", Self::LANGUAGE_SERVER_ID, truncated_checksum);
137+
fs::create_dir_all(&expert_dir).map_err(|e| format!("failed to create directory: {e}"))?;
104138

105-
let binary_path = format!("{version_dir}/expert");
139+
let binary_path = format!("{expert_dir}/expert");
106140

107141
if !fs::metadata(&binary_path).map_or(false, |stat| stat.is_file()) {
108142
zed::set_language_server_installation_status(
@@ -119,7 +153,7 @@ impl Expert {
119153

120154
zed::make_file_executable(&binary_path)?;
121155

122-
util::remove_outdated_versions(Self::LANGUAGE_SERVER_ID, &version_dir)?;
156+
util::remove_outdated_versions(Self::LANGUAGE_SERVER_ID, &expert_dir)?;
123157
}
124158

125159
self.cached_binary_path = Some(binary_path.clone());

0 commit comments

Comments
 (0)