fix(cache): improve repository cache robustness (#6689)

This commit is contained in:
Rhys Arkins 2020-07-07 06:24:26 +02:00 committed by GitHub
parent e015875ac5
commit 4459b11261
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View file

@ -45,6 +45,6 @@ describe('lib/util/cache/repository', () => {
expect(fs.outputFile.mock.calls).toHaveLength(1); expect(fs.outputFile.mock.calls).toHaveLength(1);
}); });
it('gets', () => { it('gets', () => {
expect(repositoryCache.getCache()).toEqual({ repository: 'abc/def' }); expect(repositoryCache.getCache()).toEqual({});
}); });
}); });

View file

@ -56,15 +56,19 @@ export async function initialize(config: RenovateConfig): Promise<void> {
} catch (err) { } catch (err) {
logger.debug({ cacheFileName }, 'Repository cache not found'); logger.debug({ cacheFileName }, 'Repository cache not found');
} }
cache = cache || { repository: config.repository }; cache = cache || Object.create({});
cache.repository = config.repository;
} }
export function getCache(): Cache { export function getCache(): Cache {
cache = cache || Object.create({});
return cache; return cache;
} }
export async function finalize(): Promise<void> { export async function finalize(): Promise<void> {
if (repositoryCache !== 'disabled') { if (cacheFileName && cache && repositoryCache !== 'disabled') {
await fs.outputFile(cacheFileName, JSON.stringify(cache)); await fs.outputFile(cacheFileName, JSON.stringify(cache));
} }
cacheFileName = null;
cache = Object.create({});
} }