@@ -205,7 +205,11 @@ async function getProjectGhcVersion(
205
205
return callWrapper ( downloadedWrapper ) ;
206
206
}
207
207
208
- async function getReleaseMetadata ( context : ExtensionContext , storagePath : string ) : Promise < IRelease [ ] | null > {
208
+ async function getReleaseMetadata (
209
+ context : ExtensionContext ,
210
+ storagePath : string ,
211
+ logger : Logger
212
+ ) : Promise < IRelease [ ] | null > {
209
213
const releasesUrl = workspace . getConfiguration ( 'haskell' ) . releasesURL
210
214
? url . parse ( workspace . getConfiguration ( 'haskell' ) . releasesURL )
211
215
: undefined ;
@@ -220,6 +224,25 @@ async function getReleaseMetadata(context: ExtensionContext, storagePath: string
220
224
} ;
221
225
222
226
const offlineCache = path . join ( storagePath , 'approvedReleases.cache.json' ) ;
227
+ const offlineCacheOldFormat = path . join ( storagePath , 'latestApprovedRelease.cache.json' ) ;
228
+
229
+ // Migrate existing old cache file latestApprovedRelease.cache.json to the new cache file
230
+ // approvedReleases.cache.json if no such file exists yet.
231
+ if ( ! fs . existsSync ( offlineCache ) ) {
232
+ try {
233
+ const oldCachedInfo = await promisify ( fs . readFile ) ( offlineCacheOldFormat , { encoding : 'utf-8' } ) ;
234
+ const oldCachedInfoParsed = validate . parseAndValidate ( oldCachedInfo , validate . optional ( releaseValidator ) ) ;
235
+ if ( oldCachedInfoParsed !== null ) {
236
+ await promisify ( fs . writeFile ) ( offlineCache , JSON . stringify ( [ oldCachedInfoParsed ] ) , { encoding : 'utf-8' } ) ;
237
+ }
238
+ logger . info ( `Successfully migrated ${ offlineCacheOldFormat } to ${ offlineCache } ` ) ;
239
+ } catch ( err : any ) {
240
+ // Ignore if old cache file does not exist
241
+ if ( err . code !== 'ENOENT' ) {
242
+ logger . error ( `Failed to migrate ${ offlineCacheOldFormat } to ${ offlineCache } : ${ err } ` ) ;
243
+ }
244
+ }
245
+ }
223
246
224
247
async function readCachedReleaseData ( ) : Promise < IRelease [ ] | null > {
225
248
try {
@@ -317,7 +340,7 @@ export async function downloadHaskellLanguageServer(
317
340
}
318
341
319
342
logger . info ( 'Fetching the latest release from GitHub or from cache' ) ;
320
- const releases = await getReleaseMetadata ( context , storagePath ) ;
343
+ const releases = await getReleaseMetadata ( context , storagePath , logger ) ;
321
344
if ( ! releases ) {
322
345
let message = "Couldn't find any pre-built haskell-language-server binaries" ;
323
346
const updateBehaviour = workspace . getConfiguration ( 'haskell' ) . get ( 'updateBehavior' ) as UpdateBehaviour ;
0 commit comments