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

Overwrite files when extracting with GNU tar #717

Closed
wants to merge 1 commit into from
Closed

Overwrite files when extracting with GNU tar #717

wants to merge 1 commit into from

Conversation

stmcginnis
Copy link

When using GNU tar, if a file already exists, from a previous run or
another cached action, it results in a slew of warning messages that
can cause issues for the run.

Non-GNU versions appear to automatically overwrite existing files.
From the BSD tar manpage:

-x    Extract to disk from the archive.  If a file with the same name
      appears more than once in the archive, each copy will be
      extracted, with later copies overwriting (replacing) earlier
      copies.

This change adds the use of --overwrite when using GNU tar so that
any existing files will just be overwritten as well.

This is to help address issues encountered with golangci/golangci-lint-action
documented here:

golangci/golangci-lint-action#135

When using GNU tar, if a file already exists, from a previous run or
another cached action, it results in a slew of warning messages that
can cause issues for the run.

Non-GNU versions appear to automatically overwrite existing files.
From the BSD tar manpage:

```
-x    Extract to disk from the archive.  If a file with the same name
      appears more than once in the archive, each copy will be
      extracted, with later copies overwriting (replacing) earlier
      copies.
```

This change adds the use of `--overwrite` when using GNU tar so that
any existing files will just be overwritten as well.

Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
@thboop
Copy link
Collaborator

thboop commented May 24, 2021

Closing in favor of #807, will release a new version this week

@StevenACoffman
Copy link

Hi. This doesn't appear to be fully resolved.

As I can see the extractTar function is imported from internal package: https://github.com/actions/toolkit/blob/main/packages/cache/src/cache.ts#L5 and the internal implementation does not contain --overwrite flag:

export async function extractTar(
archivePath: string,
compressionMethod: CompressionMethod
): Promise<void> {
// Create directory to extract tar into
const workingDirectory = getWorkingDirectory()
await io.mkdirP(workingDirectory)
// --d: Decompress.
// --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
// Using 30 here because we also support 32-bit self-hosted runners.
function getCompressionProgram(): string[] {
switch (compressionMethod) {
case CompressionMethod.Zstd:
return ['--use-compress-program', 'zstd -d --long=30']
case CompressionMethod.ZstdWithoutLong:
return ['--use-compress-program', 'zstd -d']
default:
return ['-z']
}
}
const args = [
...getCompressionProgram(),
'-xf',
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P',
'-C',
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
]
await execTar(args, compressionMethod)
}

so there is no way to fix the issue within this action, while GitHub Action uses tar without --overwrite flag.

@hermanbanken
Copy link

Can confirm this isn't fixed.
The golangci-lint action which is using toolkit cache, can't be fixed if this isn't addressed. See: golangci/golangci-lint-action#244

@StevenACoffman
Copy link

Fairly sure no one is looking at comments on old closed issues, so a new issue and an accompanying PR is probably the best chance to get this resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants