From 4cf255df101c05f3bf458427ca40e45fa872bfd8 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Thu, 21 Oct 2021 11:11:55 -0600 Subject: [PATCH] Move bundle metadata files out of `caches` directory Instead, use a separate '.gradle-build-action' directory for bundle metadata files. This directory is always part of the cache-path. --- src/cache-gradle-user-home.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/cache-gradle-user-home.ts b/src/cache-gradle-user-home.ts index 3ebbf4e..cd7d931 100644 --- a/src/cache-gradle-user-home.ts +++ b/src/cache-gradle-user-home.ts @@ -12,6 +12,8 @@ import { tryDelete } from './cache-utils' +const META_FILE_DIR = '.gradle-build-action' + export class GradleUserHomeCache extends AbstractCache { private gradleUserHome: string @@ -65,11 +67,7 @@ export class GradleUserHomeCache extends AbstractCache { } private getBundleMetaFile(name: string): string { - return path.resolve( - this.gradleUserHome, - 'caches', - `.gradle-build-action.${name}.cache` - ) + return path.resolve(this.gradleUserHome, META_FILE_DIR, `${name}.cache`) } async beforeSave(): Promise { @@ -142,9 +140,7 @@ export class GradleUserHomeCache extends AbstractCache { } else { core.info(`Caching ${bundle} with cache key: ${cacheKey}`) await this.saveCache([artifactPath], cacheKey) - - this.debug(`Writing cache metafile: ${bundleMetaFile}`) - fs.writeFileSync(bundleMetaFile, cacheKey) + this.writeBundleMetaFile(bundleMetaFile, cacheKey) } for (const file of bundleFiles) { @@ -166,6 +162,17 @@ export class GradleUserHomeCache extends AbstractCache { return `${cacheKeyPrefix}${bundle}-${key}` } + private writeBundleMetaFile(metaFile: string, cacheKey: string): void { + this.debug(`Writing bundle metafile: ${metaFile}`) + + const dirName = path.dirname(metaFile) + if (!fs.existsSync(dirName)) { + fs.mkdirSync(dirName) + } + + fs.writeFileSync(metaFile, cacheKey) + } + protected determineGradleUserHome(rootDir: string): string { const customGradleUserHome = process.env['GRADLE_USER_HOME'] if (customGradleUserHome) {