From f2bb19b43ac214584bbfb4a41318247fd3eca618 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Sat, 28 May 2022 18:10:35 -0600 Subject: [PATCH] Remove downloaded wrapper zips before caching The wrapper zip files are redundant, and not required after extraction. Gradle 7.5+ will delete these automatically, but we delete them for older versions to avoid caching the wrapper distributions twice. Sinc the `gradle-home-cache-excludes` parameter does not support wildcards, we remove them explicitly. --- src/cache-extract-entries.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cache-extract-entries.ts b/src/cache-extract-entries.ts index 1a9acf9..657d0ce 100644 --- a/src/cache-extract-entries.ts +++ b/src/cache-extract-entries.ts @@ -294,6 +294,28 @@ export class GradleHomeEntryExtractor extends AbstractEntryExtractor { super(gradleUserHome, 'gradle-home') } + async extract(listener: CacheListener): Promise { + await this.deleteWrapperZips() + return super.extract(listener) + } + + /** + * Delete any downloaded wrapper zip files that are not needed after extraction. + * These files are cleaned up by Gradle >= 7.5, but for older versions we remove them manually. + */ + private async deleteWrapperZips(): Promise { + const wrapperZips = path.resolve(this.gradleUserHome, 'wrapper/dists/*/*/*.zip') + const globber = await glob.create(wrapperZips, { + implicitDescendants: false, + followSymbolicLinks: false + }) + + for (const p of await globber.glob()) { + cacheDebug(`Deleting wrapper zip: ${p}`) + tryDelete(p) + } + } + /** * Return the extracted cache entry definitions, which determine which artifacts will be cached * separately from the rest of the Gradle User Home cache entry. @@ -316,7 +338,7 @@ export class GradleHomeEntryExtractor extends AbstractEntryExtractor { return [ entryDefinition('generated-gradle-jars', ['caches/*/generated-gradle-jars/*.jar'], false), - entryDefinition('wrapper-zips', ['wrapper/dists/*/*/*/'], false), // Directories only + entryDefinition('wrapper-zips', ['wrapper/dists/*/*/'], false), // Entire wrapper directory cached together entryDefinition('java-toolchains', ['jdks/*.zip', 'jdks/*.tar.gz'], false), entryDefinition('dependencies', ['caches/modules-*/files-*/*/*/*/*'], true), entryDefinition('instrumented-jars', ['caches/jars-*/*'], true),