@@ -39,6 +39,8 @@ const githubReleaseApiValidator: validate.Validator<IRelease[]> = validate.array
39
39
40
40
const cachedReleaseValidator : validate . Validator < IRelease [ ] | null > = validate . optional ( githubReleaseApiValidator ) ;
41
41
42
+ const cachedReleaseValidatorOld : validate . Validator < IRelease | null > = validate . optional ( releaseValidator ) ;
43
+
42
44
// On Windows the executable needs to be stored somewhere with an .exe extension
43
45
const exeExt = process . platform === 'win32' ? '.exe' : '' ;
44
46
@@ -221,10 +223,36 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
221
223
222
224
const offlineCache = path . join ( storagePath , 'approvedReleases.cache.json' ) ;
223
225
224
- async function readCachedReleaseData ( ) : Promise < IRelease [ ] | null > {
226
+ async function readCachedReleaseData ( fallBack : boolean ) : Promise < IRelease [ ] | null > {
225
227
try {
226
228
const cachedInfo = await promisify ( fs . readFile ) ( offlineCache , { encoding : 'utf-8' } ) ;
227
229
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
+ }
228
256
} catch ( err : any ) {
229
257
// If file doesn't exist, return null, otherwise consider it a failure
230
258
if ( err . code === 'ENOENT' ) {
@@ -233,11 +261,12 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
233
261
throw err ;
234
262
}
235
263
}
264
+
236
265
// Not all users want to upgrade right away, in that case prompt
237
266
const updateBehaviour = workspace . getConfiguration ( 'haskell' ) . get ( 'updateBehavior' ) as UpdateBehaviour ;
238
267
239
268
if ( updateBehaviour === 'never-check' ) {
240
- return readCachedReleaseData ( ) ;
269
+ return readCachedReleaseData ( true )
241
270
}
242
271
243
272
try {
@@ -246,7 +275,7 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
246
275
validate . parseAndValidate ( releaseInfo , githubReleaseApiValidator ) . filter ( ( x ) => ! x . prerelease ) || null ;
247
276
248
277
if ( updateBehaviour === 'prompt' ) {
249
- const cachedInfoParsed = await readCachedReleaseData ( ) ;
278
+ const cachedInfoParsed = await readCachedReleaseData ( false ) ;
250
279
251
280
if (
252
281
releaseInfoParsed !== null && releaseInfoParsed . length > 0 &&
@@ -261,7 +290,7 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
261
290
const decision = await window . showInformationMessage ( promptMessage , 'Download' , 'Nevermind' ) ;
262
291
if ( decision !== 'Download' ) {
263
292
// If not upgrade, bail and don't overwrite cached version information
264
- return cachedInfoParsed ;
293
+ return readCachedReleaseData ( true ) ;
265
294
}
266
295
}
267
296
}
@@ -272,7 +301,7 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
272
301
} catch ( githubError : any ) {
273
302
// Attempt to read from the latest cached file
274
303
try {
275
- const cachedInfoParsed = await readCachedReleaseData ( ) ;
304
+ const cachedInfoParsed = await readCachedReleaseData ( true ) ;
276
305
277
306
window . showWarningMessage (
278
307
`Couldn't get the latest haskell-language-server releases from GitHub, used local cache instead:\n${ githubError . message } `
0 commit comments