-
Notifications
You must be signed in to change notification settings - Fork 145
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
Add support for JRE provisioning: Jre tar.gz unpack #2036
Add support for JRE provisioning: Jre tar.gz unpack #2036
Conversation
8eeed83
to
0aee8b5
Compare
11cf39a
to
173a9d7
Compare
03d3f67
to
19e40b6
Compare
tar.CopyEntryContents(outputStream); | ||
|
||
#if NETSTANDARD | ||
if (operatingSystemProvider.OperatingSystem() is PlatformOS.Linux or PlatformOS.Alpine) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this section cannot be covered by tests, since we run tests only targeting .NET Framework 4.6.2.
19e40b6
to
282751a
Compare
ffd1271
to
f3a994b
Compare
src/SonarScanner.MSBuild.PreProcessor/JreCaching/UnpackerFactory.cs
Outdated
Show resolved
Hide resolved
src/SonarScanner.MSBuild.PreProcessor/JreCaching/TarGzUnpacker.cs
Outdated
Show resolved
Hide resolved
src/SonarScanner.MSBuild.PreProcessor/JreCaching/TarGzUnpacker.cs
Outdated
Show resolved
Hide resolved
9efd04b
to
7138c77
Compare
7138c77
to
7dc4ab4
Compare
Tests/SonarScanner.MSBuild.PreProcessor.Test/JreCaching/TarGzUnpackTests.cs
Outdated
Show resolved
Hide resolved
}; | ||
|
||
private static bool IsTarball(string filename) => | ||
string.Equals(Path.GetExtension(Path.GetFileNameWithoutExtension(filename)), ".tar", StringComparison.OrdinalIgnoreCase); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like the fact that we have to call ToUpperInvariant and also that we do an indirect string match. Part in the Create method and part in IsTarball.
What do you think about rewriting the Create method body to:
archive switch
{
_ when archive.EndsWith(".ZIP", StringComparison.OrdinalIgnoreCase) => new ZipUnpacker(),
_ when archive.EndsWith(".TAR.GZ", StringComparison.OrdinalIgnoreCase) => new TarGzUnpacker(directoryWrapper, fileWrapper, operatingSystemProvider),
_ => null
};
I would also rename archive
to archivePath
or something similar to better explain that it's the file name and not the content of the archive.
var destinationFullPath = Path.GetFullPath(destinationDirectory).TrimEnd('/', '\\'); | ||
while (tarIn.GetNextEntry() is {} entry) | ||
{ | ||
if (entry.TarHeader.TypeFlag is not TarHeader.LF_LINK or TarHeader.LF_SYMLINK) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (entry.TarHeader.TypeFlag is not TarHeader.LF_LINK or TarHeader.LF_SYMLINK) | |
if (entry.TarHeader.TypeFlag is not TarHeader.LF_LINK and not TarHeader.LF_SYMLINK) |
or
if (entry.TarHeader.TypeFlag is not TarHeader.LF_LINK or TarHeader.LF_SYMLINK) | |
if (entry.TarHeader.TypeFlag is not (TarHeader.LF_LINK or TarHeader.LF_SYMLINK)) |
{ | ||
_ = new Mono.Unix.UnixFileInfo(destinationFile) | ||
{ | ||
FileAccessPermissions = (Mono.Unix.FileAccessPermissions)entry.TarHeader.Mode // set the same permissions as inside the archive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martin-strecker-sonarsource, the reason why we don't use TarArchive.CreateInputTarArchive(tarIn).EtractContents();
is to be able to copy the file permission settimgs? (just trying to understand the use case)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The alternative is to use EtractContents
(which has path traversal protection) and do a second pass, where we do the permission setting (and we know in the second pass that there is no path traversal in the archive).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fine to do it like this, as it is not that big and it is quite readable.
src/SonarScanner.MSBuild.PreProcessor/SonarScanner.MSBuild.PreProcessor.csproj
Outdated
Show resolved
Hide resolved
…tion fails. (#2033) Add logging and log assertions. Implement and test zip unpack. Add assertion Remove verbatim string token Normalize line endings Fix doc comment NewLine Fix doc comment Revert change in UT after re-base Add unpackProvider dependency to JreCache Use TryGetUnpack early to bail out. Unpack provider integration tests Add comments Add zipslip test Assert good file as well Add ExtractToDirectory Re-work to use "ExtractToDirectory" which handles all kind of cases much better than we can do. Implement UnpackJre in JreCache Fix flow and assertions Add success test Add more assertions Add TODOs Add temp folder clean up and tests Add todos Add Unpack_Failure_JavaExeNotFound Fx todo Cleanup Add EndToEndTestWithFiles_Success test Fix path in JreDescriptor Newlines Apply suggestions from code review Move NormalizeLineEndings to test project Reename IUnpackProvider to IUnpackerFactory Rename IUnpack to IUnpacker Rename factory method Rename GetUnpackForArchive to CreateForArchive Use resx for all messages Fix tests after rename Return null instead of throw for CreateForArchive Simplify CreateForArchive call handling Exract path caclualtions Remove string.Format Re-arrange log assertions in UnpackerFactory_Success and add comment Remove file init Add result assertion to EndToEndTestWithFiles_Success Inline substitutes in UnpackerFactoryTests Use Directory.Delete(.., true) for cleanup. Simplify file/directoy assertions in EndToEndTestWithFiles_Success Fixes after re-base Remove outdated comment
20f7e0b
to
49e4434
Compare
Tests/SonarScanner.MSBuild.PreProcessor.Test/JreCaching/TarGzUnpackTests.cs
Outdated
Show resolved
Hide resolved
Tests/SonarScanner.MSBuild.PreProcessor.Test/JreCaching/TarGzUnpackTests.cs
Outdated
Show resolved
Hide resolved
src/SonarScanner.MSBuild.PreProcessor/JreCaching/TarGzUnpacker.cs
Outdated
Show resolved
Hide resolved
@costin-zaharia-sonarsource just FYI: |
207e214
to
6f8c584
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nut a few more tests are needed.
Tests/SonarScanner.MSBuild.PreProcessor.Test/JreCaching/JreCacheTests.cs
Show resolved
Hide resolved
Tests/SonarScanner.MSBuild.PreProcessor.Test/JreCaching/TarGzUnpackTests.cs
Show resolved
Hide resolved
Quality Gate passedIssues Measures |
Fixes #2031