Skip to content

Commit

Permalink
big fuckup
Browse files Browse the repository at this point in the history
  • Loading branch information
santisq committed Jan 10, 2025
1 parent edb8e27 commit 8782681
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 78 deletions.
2 changes: 1 addition & 1 deletion docs/en-US/Get-ZipEntry.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Archive 2/22/2024 1:19 PM 1.55 KB 5.35 KB Set-ZipEnt

```powershell
PS ..\pwsh> $package = Invoke-WebRequest https://www.powershellgallery.com/api/v2/package/PSCompression
PS ..\pwsh> $package | Get-ZipEntry
PS ..\pwsh> $package | Get-ZipEntry | Select-Object -First 5
Directory: /
Expand Down
4 changes: 4 additions & 0 deletions src/PSCompression/Commands/ConvertFromGzipStringCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ protected override void ProcessRecord()
WriteObject(reader.ReadLine());
}
}
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (Exception exception)
{
WriteError(exception.ToEnumerationError(line));
Expand Down
4 changes: 4 additions & 0 deletions src/PSCompression/Commands/ConvertToGzipStringCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ protected override void EndProcessing()

WriteObject(Convert.ToBase64String(_outstream.ToArray()));
}
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (Exception exception)
{
WriteError(exception.ToWriteError(_outstream));
Expand Down
4 changes: 4 additions & 0 deletions src/PSCompression/Commands/ExpandGzipArchiveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ protected override void ProcessRecord()
encoding: Encoding,
cmdlet: this);
}
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (Exception exception)
{
WriteError(exception.ToOpenError(path));
Expand Down
8 changes: 7 additions & 1 deletion src/PSCompression/Commands/ExpandZipEntryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ protected override void BeginProcessing()
if (Destination.IsArchive())
{
ThrowTerminatingError(
ExceptionHelper.NotDirectoryPath(Destination, nameof(Destination)));
ExceptionHelper.NotDirectoryPath(
Destination,
nameof(Destination)));
}

if (!Directory.Exists(Destination))
Expand Down Expand Up @@ -67,6 +69,10 @@ protected override void ProcessRecord()
WriteObject(new DirectoryInfo(path));
}
}
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (Exception exception)
{
WriteError(exception.ToExtractEntryError(entry));
Expand Down
8 changes: 8 additions & 0 deletions src/PSCompression/Commands/GetZipEntryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ ZipEntryBase CreateFromStream(ZipArchiveEntry entry, bool isDirectory) =>
WriteObject(entries, enumerateCollection: true);
return;
}
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (InvalidDataException exception)
{
ThrowTerminatingError(exception.ToInvalidZipArchive());
Expand Down Expand Up @@ -122,6 +126,10 @@ ZipEntryBase CreateFromFile(ZipArchiveEntry entry, bool isDirectory) =>

WriteObject(entries, enumerateCollection: true);
}
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (InvalidDataException exception)
{
ThrowTerminatingError(exception.ToInvalidZipArchive());
Expand Down
4 changes: 4 additions & 0 deletions src/PSCompression/Commands/GetZipEntryContentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ protected override void ProcessRecord()
ZipContentReader reader = new(GetOrAdd(entry));
ReadEntry(entry, reader);
}
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (Exception exception)
{
WriteError(exception.ToOpenError(entry.Source));
Expand Down
12 changes: 11 additions & 1 deletion src/PSCompression/Commands/NewZipEntryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ protected override void BeginProcessing()
if (!SourcePath.IsArchive())
{
ThrowTerminatingError(
ExceptionHelper.NotArchivePath(SourcePath, nameof(SourcePath)));
ExceptionHelper.NotArchivePath(
SourcePath,
nameof(SourcePath)));
}

using FileStream fileStream = File.Open(
Expand Down Expand Up @@ -136,6 +138,10 @@ protected override void BeginProcessing()
compressionLevel: CompressionLevel));
}
}
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (Exception exception)
{
ThrowTerminatingError(exception.ToOpenError(Destination));
Expand Down Expand Up @@ -185,6 +191,10 @@ protected override void EndProcessing()
_zip?.Dispose();
WriteObject(GetResult(), enumerateCollection: true);
}
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (Exception exception)
{
ThrowTerminatingError(exception.ToOpenError(Destination));
Expand Down
5 changes: 5 additions & 0 deletions src/PSCompression/Commands/RemoveZipEntryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace PSCompression.Commands;

[Cmdlet(VerbsCommon.Remove, "ZipEntry", SupportsShouldProcess = true)]
[OutputType(typeof(void))]
public sealed class RemoveZipEntryCommand : PSCmdlet, IDisposable
{
private readonly ZipArchiveCache _cache = new(ZipArchiveMode.Update);
Expand All @@ -24,6 +25,10 @@ protected override void ProcessRecord()
entry.Remove(_cache.GetOrAdd(entry));
}
}
catch (Exception _) when (_ is PipelineStoppedException or FlowControlException)
{
throw;
}
catch (NotSupportedException exception)
{
ThrowTerminatingError(exception.ToStreamOpenError(entry));
Expand Down
77 changes: 2 additions & 75 deletions src/PSCompression/Extensions/PathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,79 +19,6 @@ public static class PathExtensions

private const string _directorySeparator = "/";

// [ThreadStatic]
// private static List<string>? s_normalizedPaths;

// internal static string[] NormalizePath(
// this string[] paths,
// bool isLiteral,
// PSCmdlet cmdlet,
// bool throwOnInvalidProvider = false)
// {
// s_normalizedPaths ??= [];
// Collection<string> resolvedPaths;
// ProviderInfo provider;
// s_normalizedPaths.Clear();

// foreach (string path in paths)
// {
// if (isLiteral)
// {
// string resolvedPath = cmdlet
// .SessionState.Path
// .GetUnresolvedProviderPathFromPSPath(path, out provider, out _);

// if (!provider.IsFileSystem())
// {
// if (throwOnInvalidProvider)
// {
// cmdlet.ThrowTerminatingError(provider.ToInvalidProviderError(path));
// }

// cmdlet.WriteError(provider.ToInvalidProviderError(path));
// continue;
// }

// s_normalizedPaths.Add(resolvedPath);
// continue;
// }

// try
// {
// resolvedPaths = cmdlet.GetResolvedProviderPathFromPSPath(path, out provider);

// foreach (string resolvedPath in resolvedPaths)
// {
// if (!provider.IsFileSystem())
// {
// cmdlet.WriteError(provider.ToInvalidProviderError(resolvedPath));
// continue;
// }

// s_normalizedPaths.Add(resolvedPath);
// }
// }
// catch (Exception exception)
// {

// cmdlet.WriteError(exception.ToResolvePathError(path));
// }
// }

// return [.. s_normalizedPaths];
// }

// internal static string NormalizePath(
// this string path,
// bool isLiteral,
// PSCmdlet cmdlet,
// bool throwOnInvalidProvider = false) =>
// NormalizePath([path], isLiteral, cmdlet, throwOnInvalidProvider)
// .FirstOrDefault();

// internal static bool IsFileSystem(this ProviderInfo provider) =>
// provider.ImplementingType == typeof(FileSystemProvider);

internal static string ResolvePath(this string path, PSCmdlet cmdlet)
{
string resolved = cmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
Expand Down Expand Up @@ -150,6 +77,6 @@ internal static bool IsDirectoryPath(this string path) =>

public static string NormalizePath(this string path) =>
s_reEntryDir.IsMatch(path)
? NormalizeEntryPath(path)
: NormalizeFileEntryPath(path);
? NormalizeEntryPath(path)
: NormalizeFileEntryPath(path);
}

0 comments on commit 8782681

Please sign in to comment.