Skip to content

Commit

Permalink
Review 2
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-paidis-sonarsource committed Jul 11, 2024
1 parent 3576608 commit 49e4434
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ namespace SonarScanner.MSBuild.PreProcessor.JreCaching;

public interface IUnpackerFactory
{
IUnpacker Create(IDirectoryWrapper directoryWrapper, IFileWrapper fileWrapper, IOperatingSystemProvider operatingSystemProvider, string archive);
IUnpacker Create(IDirectoryWrapper directoryWrapper, IFileWrapper fileWrapper, IOperatingSystemProvider operatingSystemProvider, string archivePath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

using System;
using System.IO;
using SonarScanner.MSBuild.Common;

namespace SonarScanner.MSBuild.PreProcessor.JreCaching;
Expand All @@ -28,14 +27,11 @@ public class UnpackerFactory : IUnpackerFactory
{
public static UnpackerFactory Instance { get; } = new UnpackerFactory();

public IUnpacker Create(IDirectoryWrapper directoryWrapper, IFileWrapper fileWrapper, IOperatingSystemProvider operatingSystemProvider, string archive) =>
Path.GetExtension(archive).ToUpperInvariant() switch
public IUnpacker Create(IDirectoryWrapper directoryWrapper, IFileWrapper fileWrapper, IOperatingSystemProvider operatingSystemProvider, string archivePath) =>
archivePath switch
{
".ZIP" => new ZipUnpacker(),
".GZ" when IsTarball(archive) => new TarGzUnpacker(directoryWrapper, fileWrapper, operatingSystemProvider),
_ when archivePath.EndsWith(".ZIP", StringComparison.OrdinalIgnoreCase) => new ZipUnpacker(),
_ when archivePath.EndsWith(".TAR.GZ", StringComparison.OrdinalIgnoreCase) => new TarGzUnpacker(directoryWrapper, fileWrapper, operatingSystemProvider),
_ => null
};

private static bool IsTarball(string filename) =>
string.Equals(Path.GetExtension(Path.GetFileNameWithoutExtension(filename)), ".tar", StringComparison.OrdinalIgnoreCase);
}

0 comments on commit 49e4434

Please sign in to comment.