Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] tool-cache: in tc.cacheDir() and tc.cacheFile(), allow the user to opt-in to preserving timestamps when copying #1617

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
32 changes: 19 additions & 13 deletions packages/tool-cache/src/tool-cache.ts
Expand Up @@ -409,19 +409,22 @@ async function extractZipNix(file: string, dest: string): Promise<void> {
/**
* Caches a directory and installs it into the tool cacheDir
*
* @param sourceDir the directory to cache into tools
* @param tool tool name
* @param version version of the tool. semver format
* @param arch architecture of the tool. Optional. Defaults to machine architecture
* @param sourceDir the directory to cache into tools
* @param tool tool name
* @param version version of the tool. semver format
* @param arch architecture of the tool. Optional. Defaults to machine architecture
# @param preserveTimestamps whether to preserve timestamps when copying. Optional. Defaults to true
DilumAluthge marked this conversation as resolved.
Show resolved Hide resolved
*/
export async function cacheDir(
sourceDir: string,
tool: string,
version: string,
arch?: string
arch?: string,
preserveTimestamps?: boolean
): Promise<string> {
version = semver.clean(version) || version
arch = arch || os.arch()
preserveTimestamps = preserveTimestamps || true
core.debug(`Caching tool ${tool} ${version} ${arch}`)

core.debug(`source dir: ${sourceDir}`)
Expand All @@ -435,7 +438,7 @@ export async function cacheDir(
// due to anti-virus software having an open handle on a file.
for (const itemName of fs.readdirSync(sourceDir)) {
const s = path.join(sourceDir, itemName)
await io.cp(s, destPath, {recursive: true})
await io.cp(s, destPath, {recursive: true, preserveTimestamps: preserveTimestamps})
DilumAluthge marked this conversation as resolved.
Show resolved Hide resolved
DilumAluthge marked this conversation as resolved.
Show resolved Hide resolved
}

// write .complete
Expand All @@ -448,21 +451,24 @@ export async function cacheDir(
* Caches a downloaded file (GUID) and installs it
* into the tool cache with a given targetName
*
* @param sourceFile the file to cache into tools. Typically a result of downloadTool which is a guid.
* @param targetFile the name of the file name in the tools directory
* @param tool tool name
* @param version version of the tool. semver format
* @param arch architecture of the tool. Optional. Defaults to machine architecture
* @param sourceFile the file to cache into tools. Typically a result of downloadTool which is a guid.
* @param targetFile the name of the file name in the tools directory
* @param tool tool name
* @param version version of the tool. semver format
* @param arch architecture of the tool. Optional. Defaults to machine architecture
# @param preserveTimestamps whether to preserve timestamps when copying. Optional. Defaults to true
DilumAluthge marked this conversation as resolved.
Show resolved Hide resolved
*/
export async function cacheFile(
sourceFile: string,
targetFile: string,
tool: string,
version: string,
arch?: string
arch?: string,
preserveTimestamps?: boolean
): Promise<string> {
version = semver.clean(version) || version
arch = arch || os.arch()
preserveTimestamps = preserveTimestamps || true
core.debug(`Caching tool ${tool} ${version} ${arch}`)

core.debug(`source file: ${sourceFile}`)
Expand All @@ -477,7 +483,7 @@ export async function cacheFile(
// anti-virus software having an open handle on a file.
const destPath: string = path.join(destFolder, targetFile)
core.debug(`destination file ${destPath}`)
await io.cp(sourceFile, destPath)
await io.cp(sourceFile, destPath, {preserveTimestamps: preserveTimestamps})
DilumAluthge marked this conversation as resolved.
Show resolved Hide resolved

// write .complete
_completeToolPath(tool, version, arch)
Expand Down