mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-07 16:56:12 +02:00
Allow time for processes to release file locks on windows
This commit is contained in:
parent
c000a0b58f
commit
4968d2280b
2 changed files with 27 additions and 3 deletions
|
@ -3,6 +3,7 @@ import * as cache from '@actions/cache'
|
|||
import * as github from '@actions/github'
|
||||
import * as crypto from 'crypto'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
|
||||
export function isCacheDisabled(): boolean {
|
||||
return core.getBooleanInput('cache-disabled')
|
||||
|
@ -60,6 +61,29 @@ export function hashFileNames(fileNames: string[]): string {
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to delete a file, waiting to allow locks to be released
|
||||
*/
|
||||
export async function tryDelete(file: string): Promise<void> {
|
||||
for (let count = 0; count < 3; count++) {
|
||||
try {
|
||||
fs.unlinkSync(file)
|
||||
return
|
||||
} catch (error) {
|
||||
if (count === 2) {
|
||||
throw error
|
||||
} else {
|
||||
core.warning(String(error))
|
||||
await delay(1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function delay(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
class CacheKey {
|
||||
key: string
|
||||
restoreKeys: string[]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue