From cc6833ae1b06e6032fcca49d8d170e65b75587f7 Mon Sep 17 00:00:00 2001 From: Dominion Date: Sun, 11 Jun 2023 13:32:08 -0400 Subject: [PATCH] Fix ZipToDirectory closing the input streams --- src/Tgstation.Server.Host/IO/DefaultIOManager.cs | 10 +++++++++- src/Tgstation.Server.Host/IO/IIOManager.cs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Tgstation.Server.Host/IO/DefaultIOManager.cs b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs index 345fdd877d..a253addc93 100644 --- a/src/Tgstation.Server.Host/IO/DefaultIOManager.cs +++ b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs @@ -292,7 +292,15 @@ namespace Tgstation.Server.Host.IO if (zipFile == null) throw new ArgumentNullException(nameof(zipFile)); - using var archive = new ZipArchive(zipFile, ZipArchiveMode.Read); +#if NET7_0_OR_GREATER +#warning Check if zip file seeking has been addressesed. See https://github.com/tgstation/tgstation-server/issues/1531 +#endif + + // ZipArchive does a synchronous copy on unseekable streams we want to avoid + if (!zipFile.CanSeek) + throw new ArgumentException("Stream does not support seeking!", nameof(zipFile)); + + using var archive = new ZipArchive(zipFile, ZipArchiveMode.Read, true); archive.ExtractToDirectory(path); }, cancellationToken, diff --git a/src/Tgstation.Server.Host/IO/IIOManager.cs b/src/Tgstation.Server.Host/IO/IIOManager.cs index 56a5343573..16be142e7d 100644 --- a/src/Tgstation.Server.Host/IO/IIOManager.cs +++ b/src/Tgstation.Server.Host/IO/IIOManager.cs @@ -198,7 +198,7 @@ namespace Tgstation.Server.Host.IO /// Extract a set of to a given . /// /// The path to unzip to. - /// The of the . + /// The of the . Must have set to . Will be read completely and left open. will be indeterminate. /// The for the operation. /// A representing the running operation. Task ZipToDirectory(string path, Stream zipFile, CancellationToken cancellationToken);