Skip to content

Add IsNonCompressedTarball method to Compressor interface#122

Closed
mdzhigarov wants to merge 3 commits intocloudfoundry:developfrom
mdzhigarov:master
Closed

Add IsNonCompressedTarball method to Compressor interface#122
mdzhigarov wants to merge 3 commits intocloudfoundry:developfrom
mdzhigarov:master

Conversation

@mdzhigarov
Copy link
Contributor

@mdzhigarov mdzhigarov commented Oct 22, 2025

This PR adds a new method IsNonCompressedTarball to the Compressor interface to detect whether a file is a non-compressed tarball.

Changes

  • Added IsNonCompressedTarball(path string) (bool, error) method to the Compressor interface
  • Implemented the method in tarballCompressor using the native golang approach to inspect the tar contents
  • Implemented the method in FakeCompressor returning false for testing purposes
  • Added comprehensive unit tests covering:
    • Positive case: non-compressed tarball files
    • Negative cases: compressed tarballs and non-tarball files
    • Error handling: file command failures and execution errors

Testing

All existing tests pass and new unit tests provide comprehensive coverage of the new functionality.

- Add IsNonCompressedTarball method to Compressor interface
- Implement IsNonCompressedTarball in tarballCompressor using 'file' command
- Implement IsNonCompressedTarball in FakeCompressor returning false
- Add comprehensive unit tests for IsNonCompressedTarball functionality
- Tests cover positive/negative cases, error handling, and edge cases
}

func (c tarballCompressor) IsNonCompressedTarball(path string) (bool, error) {
stdout, _, exitStatus, err := c.cmdRunner.RunCommand("file", path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this will need to be implemented in Golang, rather than using file, or have a separate path for windows.
The agent needs to be able to function on Windows stemcells.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is ran on a windows stemcell the file command will not be found and the cmdRunner will simply return an error. That is completely fine - the tar will be treated as compressed so same behavior as today.

This would work even if the tar was originally created with the --no-compression flag. On Windows, we'd compress it again after compilation which is not a big deal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this is the likely outcome but I don't want to introduce a(nother) behavior difference between Linux and Windows.
Probably the cleanest option is to use a golang-native way to do this rather than shelling out to file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Updated the PR to detect the tar compression natively.
Tested the with bosh-agent compile on the latest lite stemcell.

@mdzhigarov mdzhigarov changed the base branch from master to develop October 22, 2025 17:39
@mdzhigarov mdzhigarov force-pushed the master branch 4 times, most recently from 79181cc to 232b93e Compare October 23, 2025 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants