From 709ded51a550bdcb37d93c879f7d59af9245c523 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Fri, 15 Oct 2021 14:54:29 -0600 Subject: [PATCH] Treat directory for instrumented jar as single artifact Leaving the `.lock` and `.receipt` files lying around was causing issues when the actual jar files were not restored. Now the entire directory will either be missing, or completely restored. --- action.yml | 2 +- src/cache-utils.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 54fc22e..a965498 100644 --- a/action.yml +++ b/action.yml @@ -38,7 +38,7 @@ inputs: ["generated-gradle-jars", "caches/*/generated-gradle-jars/*.jar"], ["wrapper-zips", "wrapper/dists/*/*/*.zip"], ["dependency-jars", "caches/modules-*/files-*/**/*.jar"], - ["instrumented-jars", "caches/jars-*/*/*.jar"] + ["instrumented-jars", "caches/jars-*/*"] ] outputs: diff --git a/src/cache-utils.ts b/src/cache-utils.ts index ad49850..e7b3a50 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -62,12 +62,17 @@ export function hashFileNames(fileNames: string[]): string { } /** - * Attempt to delete a file, waiting to allow locks to be released + * Attempt to delete a file or directory, waiting to allow locks to be released */ export async function tryDelete(file: string): Promise { + const stat = fs.lstatSync(file) for (let count = 0; count < 3; count++) { try { - fs.unlinkSync(file) + if (stat.isDirectory()) { + fs.rmdirSync(file, {recursive: true}) + } else { + fs.unlinkSync(file) + } return } catch (error) { if (count === 2) {