Skip to content

Commit 7753c4d

Browse files
committed
Revert "Fall back to old cached releases if user doesn't want to update or downloading the releases fails"
This reverts commit 15c8951.
1 parent 15c8951 commit 7753c4d

File tree

1 file changed

+5
-34
lines changed

1 file changed

+5
-34
lines changed

src/hlsBinaries.ts

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ const githubReleaseApiValidator: validate.Validator<IRelease[]> = validate.array
3939

4040
const cachedReleaseValidator: validate.Validator<IRelease[] | null> = validate.optional(githubReleaseApiValidator);
4141

42-
const cachedReleaseValidatorOld: validate.Validator<IRelease | null> = validate.optional(releaseValidator);
43-
4442
// On Windows the executable needs to be stored somewhere with an .exe extension
4543
const exeExt = process.platform === 'win32' ? '.exe' : '';
4644

@@ -223,36 +221,10 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
223221

224222
const offlineCache = path.join(storagePath, 'approvedReleases.cache.json');
225223

226-
async function readCachedReleaseData(fallBack: boolean): Promise<IRelease[] | null> {
224+
async function readCachedReleaseData(): Promise<IRelease[] | null> {
227225
try {
228226
const cachedInfo = await promisify(fs.readFile)(offlineCache, { encoding: 'utf-8' });
229227
return validate.parseAndValidate(cachedInfo, cachedReleaseValidator);
230-
} catch (err: any) {
231-
// If file doesn't exist, return null unless fallBack is true. In that case try to
232-
// read from the older cache file format (1.7.1 and earlier).
233-
// Consider everything else it a failure
234-
if (err.code === 'ENOENT') {
235-
if (fallBack) {
236-
return readOldCachedReleaseData();
237-
} else {
238-
return null;
239-
}
240-
}
241-
throw err;
242-
}
243-
}
244-
245-
const offlineCacheOld = path.join(storagePath, 'latestApprovedRelease.cache.json');
246-
247-
async function readOldCachedReleaseData(): Promise<IRelease[] | null> {
248-
try {
249-
const cachedInfo = await promisify(fs.readFile)(offlineCacheOld, { encoding: 'utf-8' });
250-
const cached = validate.parseAndValidate(cachedInfo, cachedReleaseValidatorOld);
251-
if (cached) {
252-
return [cached];
253-
} else {
254-
return null;
255-
}
256228
} catch (err: any) {
257229
// If file doesn't exist, return null, otherwise consider it a failure
258230
if (err.code === 'ENOENT') {
@@ -261,12 +233,11 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
261233
throw err;
262234
}
263235
}
264-
265236
// Not all users want to upgrade right away, in that case prompt
266237
const updateBehaviour = workspace.getConfiguration('haskell').get('updateBehavior') as UpdateBehaviour;
267238

268239
if (updateBehaviour === 'never-check') {
269-
return readCachedReleaseData(true)
240+
return readCachedReleaseData();
270241
}
271242

272243
try {
@@ -275,7 +246,7 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
275246
validate.parseAndValidate(releaseInfo, githubReleaseApiValidator).filter((x) => !x.prerelease) || null;
276247

277248
if (updateBehaviour === 'prompt') {
278-
const cachedInfoParsed = await readCachedReleaseData(false);
249+
const cachedInfoParsed = await readCachedReleaseData();
279250

280251
if (
281252
releaseInfoParsed !== null && releaseInfoParsed.length > 0 &&
@@ -290,7 +261,7 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
290261
const decision = await window.showInformationMessage(promptMessage, 'Download', 'Nevermind');
291262
if (decision !== 'Download') {
292263
// If not upgrade, bail and don't overwrite cached version information
293-
return readCachedReleaseData(true);
264+
return cachedInfoParsed;
294265
}
295266
}
296267
}
@@ -301,7 +272,7 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
301272
} catch (githubError: any) {
302273
// Attempt to read from the latest cached file
303274
try {
304-
const cachedInfoParsed = await readCachedReleaseData(true);
275+
const cachedInfoParsed = await readCachedReleaseData();
305276

306277
window.showWarningMessage(
307278
`Couldn't get the latest haskell-language-server releases from GitHub, used local cache instead:\n${githubError.message}`

0 commit comments

Comments
 (0)