From 060a1967649469fa71986dc92bb41629c0970946 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 27 Oct 2022 05:35:54 -0400 Subject: [PATCH] Use SR.Format instead of string.Format in Tar (#77528) --- .../src/System/Formats/Tar/TarEntry.cs | 24 +++++++++---------- .../src/System/Formats/Tar/TarFile.cs | 20 ++++++++-------- .../src/System/Formats/Tar/TarHeader.Read.cs | 24 +++++++++---------- .../src/System/Formats/Tar/TarHelpers.cs | 4 ++-- .../src/System/Formats/Tar/TarReader.cs | 14 +++++------ .../src/System/Formats/Tar/TarWriter.Unix.cs | 4 ++-- .../System/Formats/Tar/TarWriter.Windows.cs | 4 ++-- .../src/System/Formats/Tar/TarWriter.cs | 4 ++-- 8 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.cs index 5c08ec75f74da..61368173b0d31 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarEntry.cs @@ -199,7 +199,7 @@ public void ExtractToFile(string destinationFileName, bool overwrite) ArgumentException.ThrowIfNullOrEmpty(destinationFileName); if (EntryType is TarEntryType.SymbolicLink or TarEntryType.HardLink or TarEntryType.GlobalExtendedAttributes) { - throw new InvalidOperationException(string.Format(SR.TarEntryTypeNotSupportedForExtracting, EntryType)); + throw new InvalidOperationException(SR.Format(SR.TarEntryTypeNotSupportedForExtracting, EntryType)); } ExtractToFileInternal(destinationFileName, linkTargetPath: null, overwrite); } @@ -233,7 +233,7 @@ public Task ExtractToFileAsync(string destinationFileName, bool overwrite, Cance ArgumentException.ThrowIfNullOrEmpty(destinationFileName); if (EntryType is TarEntryType.SymbolicLink or TarEntryType.HardLink or TarEntryType.GlobalExtendedAttributes) { - return Task.FromException(new InvalidOperationException(string.Format(SR.TarEntryTypeNotSupportedForExtracting, EntryType))); + return Task.FromException(new InvalidOperationException(SR.Format(SR.TarEntryTypeNotSupportedForExtracting, EntryType))); } return ExtractToFileInternalAsync(destinationFileName, linkTargetPath: null, overwrite, cancellationToken); } @@ -254,7 +254,7 @@ public Stream? DataStream { if (!IsDataStreamSetterSupported()) { - throw new InvalidOperationException(string.Format(SR.TarEntryDoesNotSupportDataStream, Name, EntryType)); + throw new InvalidOperationException(SR.Format(SR.TarEntryDoesNotSupportDataStream, Name, EntryType)); } if (value != null && !value.CanRead) @@ -338,7 +338,7 @@ internal Task ExtractRelativeToDirectoryAsync(string destinationDirectoryPath, b string? fileDestinationPath = GetSanitizedFullPath(destinationDirectoryPath, Name); if (fileDestinationPath == null) { - throw new IOException(string.Format(SR.TarExtractingResultsFileOutside, Name, destinationDirectoryPath)); + throw new IOException(SR.Format(SR.TarExtractingResultsFileOutside, Name, destinationDirectoryPath)); } string? linkTargetPath = null; @@ -352,7 +352,7 @@ internal Task ExtractRelativeToDirectoryAsync(string destinationDirectoryPath, b linkTargetPath = GetSanitizedFullPath(destinationDirectoryPath, LinkName); if (linkTargetPath == null) { - throw new IOException(string.Format(SR.TarExtractingResultsLinkOutside, LinkName, destinationDirectoryPath)); + throw new IOException(SR.Format(SR.TarExtractingResultsLinkOutside, LinkName, destinationDirectoryPath)); } } @@ -461,7 +461,7 @@ private void CreateNonRegularFile(string filePath, string? linkTargetPath) case TarEntryType.SparseFile: case TarEntryType.TapeVolume: default: - throw new InvalidOperationException(string.Format(SR.TarEntryTypeNotSupportedForExtracting, EntryType)); + throw new InvalidOperationException(SR.Format(SR.TarEntryTypeNotSupportedForExtracting, EntryType)); } } @@ -472,7 +472,7 @@ private void VerifyPathsForEntryType(string filePath, string? linkTargetPath, bo // If the destination contains a directory segment, need to check that it exists if (!string.IsNullOrEmpty(directoryPath) && !Path.Exists(directoryPath)) { - throw new IOException(string.Format(SR.IO_PathNotFound_Path, filePath)); + throw new IOException(SR.Format(SR.IO_PathNotFound_Path, filePath)); } if (!Path.Exists(filePath)) @@ -483,13 +483,13 @@ private void VerifyPathsForEntryType(string filePath, string? linkTargetPath, bo // We never want to overwrite a directory, so we always throw if (Directory.Exists(filePath)) { - throw new IOException(string.Format(SR.IO_AlreadyExists_Name, filePath)); + throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, filePath)); } // A file exists at this point if (!overwrite) { - throw new IOException(string.Format(SR.IO_AlreadyExists_Name, filePath)); + throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, filePath)); } File.Delete(filePath); @@ -501,18 +501,18 @@ private void VerifyPathsForEntryType(string filePath, string? linkTargetPath, bo // If the destination target contains a directory segment, need to check that it exists if (!string.IsNullOrEmpty(targetDirectoryPath) && !Path.Exists(targetDirectoryPath)) { - throw new IOException(string.Format(SR.TarSymbolicLinkTargetNotExists, filePath, linkTargetPath)); + throw new IOException(SR.Format(SR.TarSymbolicLinkTargetNotExists, filePath, linkTargetPath)); } if (EntryType is TarEntryType.HardLink) { if (!Path.Exists(linkTargetPath)) { - throw new IOException(string.Format(SR.TarHardLinkTargetNotExists, filePath, linkTargetPath)); + throw new IOException(SR.Format(SR.TarHardLinkTargetNotExists, filePath, linkTargetPath)); } else if (Directory.Exists(linkTargetPath)) { - throw new IOException(string.Format(SR.TarHardLinkToDirectoryNotAllowed, filePath, linkTargetPath)); + throw new IOException(SR.Format(SR.TarHardLinkToDirectoryNotAllowed, filePath, linkTargetPath)); } } } diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarFile.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarFile.cs index 41d95ed7fd9e6..e784598cefb3a 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarFile.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarFile.cs @@ -40,7 +40,7 @@ public static void CreateFromDirectory(string sourceDirectoryName, Stream destin if (!Directory.Exists(sourceDirectoryName)) { - throw new DirectoryNotFoundException(string.Format(SR.IO_PathNotFound_Path, sourceDirectoryName)); + throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, sourceDirectoryName)); } // Rely on Path.GetFullPath for validation of paths @@ -79,7 +79,7 @@ public static Task CreateFromDirectoryAsync(string sourceDirectoryName, Stream d if (!Directory.Exists(sourceDirectoryName)) { - return Task.FromException(new DirectoryNotFoundException(string.Format(SR.IO_PathNotFound_Path, sourceDirectoryName))); + return Task.FromException(new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, sourceDirectoryName))); } // Rely on Path.GetFullPath for validation of paths @@ -109,7 +109,7 @@ public static void CreateFromDirectory(string sourceDirectoryName, string destin if (!Directory.Exists(sourceDirectoryName)) { - throw new DirectoryNotFoundException(string.Format(SR.IO_PathNotFound_Path, sourceDirectoryName)); + throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, sourceDirectoryName)); } // Throws if the destination file exists @@ -145,7 +145,7 @@ public static Task CreateFromDirectoryAsync(string sourceDirectoryName, string d if (!Directory.Exists(sourceDirectoryName)) { - return Task.FromException(new DirectoryNotFoundException(string.Format(SR.IO_PathNotFound_Path, sourceDirectoryName))); + return Task.FromException(new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, sourceDirectoryName))); } return CreateFromDirectoryInternalAsync(sourceDirectoryName, destinationFileName, includeBaseDirectory, cancellationToken); @@ -180,7 +180,7 @@ public static void ExtractToDirectory(Stream source, string destinationDirectory if (!Directory.Exists(destinationDirectoryName)) { - throw new DirectoryNotFoundException(string.Format(SR.IO_PathNotFound_Path, destinationDirectoryName)); + throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, destinationDirectoryName)); } // Rely on Path.GetFullPath for validation of paths @@ -224,7 +224,7 @@ public static Task ExtractToDirectoryAsync(Stream source, string destinationDire if (!Directory.Exists(destinationDirectoryName)) { - return Task.FromException(new DirectoryNotFoundException(string.Format(SR.IO_PathNotFound_Path, destinationDirectoryName))); + return Task.FromException(new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, destinationDirectoryName))); } // Rely on Path.GetFullPath for validation of paths @@ -260,12 +260,12 @@ public static void ExtractToDirectory(string sourceFileName, string destinationD if (!File.Exists(sourceFileName)) { - throw new FileNotFoundException(string.Format(SR.IO_FileNotFound_FileName, sourceFileName)); + throw new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, sourceFileName)); } if (!Directory.Exists(destinationDirectoryName)) { - throw new DirectoryNotFoundException(string.Format(SR.IO_PathNotFound_Path, destinationDirectoryName)); + throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, destinationDirectoryName)); } using FileStream archive = File.OpenRead(sourceFileName); @@ -306,12 +306,12 @@ public static Task ExtractToDirectoryAsync(string sourceFileName, string destina if (!File.Exists(sourceFileName)) { - return Task.FromException(new FileNotFoundException(string.Format(SR.IO_FileNotFound_FileName, sourceFileName))); + return Task.FromException(new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, sourceFileName))); } if (!Directory.Exists(destinationDirectoryName)) { - return Task.FromException(new DirectoryNotFoundException(string.Format(SR.IO_PathNotFound_Path, destinationDirectoryName))); + return Task.FromException(new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, destinationDirectoryName))); } return ExtractToDirectoryInternalAsync(sourceFileName, destinationDirectoryName, overwriteFiles, cancellationToken); diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs index 0d5ec998497f9..bda505103e6d3 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs @@ -15,8 +15,6 @@ namespace System.Formats.Tar // Reads the header attributes from a tar archive entry. internal sealed partial class TarHeader { - private const string UstarPrefixFormat = "{0}/{1}"; // "prefix/name" - // Attempts to retrieve the next header from the specified tar archive stream. // Throws if end of stream is reached or if any data type conversion fails. // Returns a valid TarHeader object if the attributes were read successfully, null otherwise. @@ -201,7 +199,7 @@ internal void ProcessDataBlock(Stream archiveStream, bool copyData) // No data section if (_size > 0) { - throw new InvalidDataException(string.Format(SR.TarSizeFieldTooLargeForEntryType, _typeFlag)); + throw new InvalidDataException(SR.Format(SR.TarSizeFieldTooLargeForEntryType, _typeFlag)); } break; case TarEntryType.RegularFile: @@ -263,7 +261,7 @@ private async Task ProcessDataBlockAsync(Stream archiveStream, bool copyData, Ca // No data section if (_size > 0) { - throw new InvalidDataException(string.Format(SR.TarSizeFieldTooLargeForEntryType, _typeFlag)); + throw new InvalidDataException(SR.Format(SR.TarSizeFieldTooLargeForEntryType, _typeFlag)); } break; case TarEntryType.RegularFile: @@ -380,7 +378,7 @@ private async Task ProcessDataBlockAsync(Stream archiveStream, bool copyData, Ca Debug.Assert(size <= TarHelpers.MaxSizeLength, "size exceeded the max value possible with 11 octal digits. Actual size " + size); if (size < 0) { - throw new InvalidDataException(string.Format(SR.TarSizeFieldNegative)); + throw new InvalidDataException(SR.Format(SR.TarSizeFieldNegative)); } // Continue with the rest of the fields that require no special checks @@ -414,7 +412,7 @@ TarEntryType.RenamedOrSymlinked or // V7 is the only one that uses 'V7RegularFile'. TarEntryType.V7RegularFile => TarEntryFormat.V7, - TarEntryType.SparseFile => throw new NotSupportedException(string.Format(SR.TarEntryTypeNotSupported, header._typeFlag)), + TarEntryType.SparseFile => throw new NotSupportedException(SR.Format(SR.TarEntryTypeNotSupported, header._typeFlag)), // We can quickly determine the *minimum* possible format if the entry type // is the POSIX 'RegularFile', although later we could upgrade it to PAX or GNU @@ -478,7 +476,7 @@ private void ReadVersionAttribute(Span buffer) // Check for gnu version header for mixed case if (!version.SequenceEqual(GnuVersionBytes)) { - throw new InvalidDataException(string.Format(SR.TarPosixFormatExpected, _name)); + throw new InvalidDataException(SR.Format(SR.TarPosixFormatExpected, _name)); } _version = GnuVersion; @@ -496,7 +494,7 @@ private void ReadVersionAttribute(Span buffer) // Check for ustar or pax version header for mixed case if (!version.SequenceEqual(UstarVersionBytes)) { - throw new InvalidDataException(string.Format(SR.TarGnuFormatExpected, _name)); + throw new InvalidDataException(SR.Format(SR.TarGnuFormatExpected, _name)); } _version = UstarVersion; @@ -557,9 +555,9 @@ private void ReadUstarAttributes(Span buffer) // Name, if the full path did not fit in the Name byte array. if (!string.IsNullOrEmpty(_prefix)) { - // Prefix never has a leading separator, so we add it - // it should always be a forward slash for compatibility - _name = string.Format(UstarPrefixFormat, _prefix, _name); + // Prefix never has a leading separator, so we add it. + // It should always be a forward slash for compatibility + _name = $"{_prefix}/{_name}"; } } @@ -615,7 +613,7 @@ private void ValidateSize() [DoesNotReturn] void ThrowSizeFieldTooLarge() => - throw new InvalidOperationException(string.Format(SR.TarSizeFieldTooLargeForEntryType, _typeFlag.ToString())); + throw new InvalidOperationException(SR.Format(SR.TarSizeFieldTooLargeForEntryType, _typeFlag.ToString())); } // Returns a dictionary containing the extended attributes collected from the provided byte buffer. @@ -627,7 +625,7 @@ private void ReadExtendedAttributesFromBuffer(ReadOnlySpan buffer, string { if (!ExtendedAttributes.TryAdd(key, value)) { - throw new InvalidDataException(string.Format(SR.TarDuplicateExtendedAttribute, name)); + throw new InvalidDataException(SR.Format(SR.TarDuplicateExtendedAttribute, name)); } } } diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHelpers.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHelpers.cs index 45cae1c275904..3d099624324d8 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHelpers.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHelpers.cs @@ -381,10 +381,10 @@ TarEntryType.RegularFile or case TarEntryFormat.Unknown: default: - throw new InvalidDataException(string.Format(SR.TarInvalidFormat, archiveFormat)); + throw new InvalidDataException(SR.Format(SR.TarInvalidFormat, archiveFormat)); } - throw new ArgumentException(string.Format(SR.TarEntryTypeNotSupportedInFormat, entryType, archiveFormat), paramName); + throw new ArgumentException(SR.Format(SR.TarEntryTypeNotSupportedInFormat, entryType, archiveFormat), paramName); } } } diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarReader.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarReader.cs index ae815dc0073b4..a8913696a9c00 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarReader.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarReader.cs @@ -401,7 +401,7 @@ TarEntryType.ExtendedAttributes or TarEntryType.LongLink or TarEntryType.LongPath) { - throw new InvalidDataException(string.Format(SR.TarUnexpectedMetadataEntry, actualHeader._typeFlag, TarEntryType.ExtendedAttributes)); + throw new InvalidDataException(SR.Format(SR.TarUnexpectedMetadataEntry, actualHeader._typeFlag, TarEntryType.ExtendedAttributes)); } // Replace all the attributes representing standard fields with the extended ones, if any @@ -433,13 +433,13 @@ TarEntryType.ExtendedAttributes or TarEntryType.LongLink or TarEntryType.LongPath) { - throw new InvalidDataException(string.Format(SR.TarUnexpectedMetadataEntry, actualHeader._typeFlag, TarEntryType.ExtendedAttributes)); + throw new InvalidDataException(SR.Format(SR.TarUnexpectedMetadataEntry, actualHeader._typeFlag, TarEntryType.ExtendedAttributes)); } // Can't have two extended attribute metadata entries in a row if (actualHeader._typeFlag is TarEntryType.ExtendedAttributes) { - throw new InvalidDataException(string.Format(SR.TarUnexpectedMetadataEntry, TarEntryType.ExtendedAttributes, TarEntryType.ExtendedAttributes)); + throw new InvalidDataException(SR.Format(SR.TarUnexpectedMetadataEntry, TarEntryType.ExtendedAttributes, TarEntryType.ExtendedAttributes)); } // Replace all the attributes representing standard fields with the extended ones, if any @@ -468,7 +468,7 @@ private bool TryProcessGnuMetadataHeader(TarHeader header, bool copyData, out Ta // Can't have two identical metadata entries in a row if (secondHeader._typeFlag == header._typeFlag) { - throw new InvalidDataException(string.Format(SR.TarUnexpectedMetadataEntry, secondHeader._typeFlag, header._typeFlag)); + throw new InvalidDataException(SR.Format(SR.TarUnexpectedMetadataEntry, secondHeader._typeFlag, header._typeFlag)); } // It's possible to have the two different metadata entries in a row @@ -486,7 +486,7 @@ private bool TryProcessGnuMetadataHeader(TarHeader header, bool copyData, out Ta // Can't have three GNU metadata entries in a row if (thirdHeader._typeFlag is TarEntryType.LongLink or TarEntryType.LongPath) { - throw new InvalidDataException(string.Format(SR.TarUnexpectedMetadataEntry, thirdHeader._typeFlag, secondHeader._typeFlag)); + throw new InvalidDataException(SR.Format(SR.TarUnexpectedMetadataEntry, thirdHeader._typeFlag, secondHeader._typeFlag)); } if (header._typeFlag is TarEntryType.LongLink) @@ -543,7 +543,7 @@ private bool TryProcessGnuMetadataHeader(TarHeader header, bool copyData, out Ta // Can't have two identical metadata entries in a row if (secondHeader._typeFlag == header._typeFlag) { - throw new InvalidDataException(string.Format(SR.TarUnexpectedMetadataEntry, secondHeader._typeFlag, header._typeFlag)); + throw new InvalidDataException(SR.Format(SR.TarUnexpectedMetadataEntry, secondHeader._typeFlag, header._typeFlag)); } TarHeader finalHeader; @@ -562,7 +562,7 @@ private bool TryProcessGnuMetadataHeader(TarHeader header, bool copyData, out Ta // Can't have three GNU metadata entries in a row if (thirdHeader._typeFlag is TarEntryType.LongLink or TarEntryType.LongPath) { - throw new InvalidDataException(string.Format(SR.TarUnexpectedMetadataEntry, thirdHeader._typeFlag, secondHeader._typeFlag)); + throw new InvalidDataException(SR.Format(SR.TarUnexpectedMetadataEntry, thirdHeader._typeFlag, secondHeader._typeFlag)); } if (header._typeFlag is TarEntryType.LongLink) diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Unix.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Unix.cs index 357e4a8a7587f..41c1b0bb9976f 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Unix.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Unix.cs @@ -35,7 +35,7 @@ private TarEntry ConstructEntryForWriting(string fullPath, string entryName, Fil Interop.Sys.FileTypes.S_IFLNK => TarEntryType.SymbolicLink, Interop.Sys.FileTypes.S_IFREG => Format is TarEntryFormat.V7 ? TarEntryType.V7RegularFile : TarEntryType.RegularFile, Interop.Sys.FileTypes.S_IFDIR => TarEntryType.Directory, - _ => throw new IOException(string.Format(SR.TarUnsupportedFile, fullPath)), + _ => throw new IOException(SR.Format(SR.TarUnsupportedFile, fullPath)), }; FileSystemInfo info = entryType is TarEntryType.Directory ? new DirectoryInfo(fullPath) : new FileInfo(fullPath); @@ -46,7 +46,7 @@ private TarEntry ConstructEntryForWriting(string fullPath, string entryName, Fil TarEntryFormat.Ustar => new UstarTarEntry(entryType, entryName), TarEntryFormat.Pax => new PaxTarEntry(entryType, entryName), TarEntryFormat.Gnu => new GnuTarEntry(entryType, entryName), - _ => throw new InvalidDataException(string.Format(SR.TarInvalidFormat, Format)), + _ => throw new InvalidDataException(SR.Format(SR.TarInvalidFormat, Format)), }; if (entryType is TarEntryType.BlockDevice or TarEntryType.CharacterDevice) diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Windows.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Windows.cs index 7452246f742ed..29905beef85e0 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Windows.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.Windows.cs @@ -36,7 +36,7 @@ private TarEntry ConstructEntryForWriting(string fullPath, string entryName, Fil } else { - throw new IOException(string.Format(SR.TarUnsupportedFile, fullPath)); + throw new IOException(SR.Format(SR.TarUnsupportedFile, fullPath)); } TarEntry entry = Format switch @@ -45,7 +45,7 @@ private TarEntry ConstructEntryForWriting(string fullPath, string entryName, Fil TarEntryFormat.Ustar => new UstarTarEntry(entryType, entryName), TarEntryFormat.Pax => new PaxTarEntry(entryType, entryName), TarEntryFormat.Gnu => new GnuTarEntry(entryType, entryName), - _ => throw new InvalidDataException(string.Format(SR.TarInvalidFormat, Format)), + _ => throw new InvalidDataException(SR.Format(SR.TarInvalidFormat, Format)), }; FileSystemInfo info = (attributes & FileAttributes.Directory) != 0 ? new DirectoryInfo(fullPath) : new FileInfo(fullPath); diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs index d7b7ceceac346..c4ec17272a8b8 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs @@ -306,7 +306,7 @@ private void WriteEntryInternal(TarEntry entry) default: Debug.Assert(entry.Format == TarEntryFormat.Unknown, "Missing format handler"); - throw new InvalidDataException(string.Format(SR.TarInvalidFormat, Format)); + throw new InvalidDataException(SR.Format(SR.TarInvalidFormat, Format)); } _wroteEntries = true; @@ -328,7 +328,7 @@ private async Task WriteEntryAsyncInternal(TarEntry entry, CancellationToken can TarEntryFormat.Pax when entry._header._typeFlag is TarEntryType.GlobalExtendedAttributes => entry._header.WriteAsPaxGlobalExtendedAttributesAsync(_archiveStream, buffer, _nextGlobalExtendedAttributesEntryNumber++, cancellationToken), TarEntryFormat.Pax => entry._header.WriteAsPaxAsync(_archiveStream, buffer, cancellationToken), TarEntryFormat.Gnu => entry._header.WriteAsGnuAsync(_archiveStream, buffer, cancellationToken), - _ => throw new InvalidDataException(string.Format(SR.TarInvalidFormat, Format)), + _ => throw new InvalidDataException(SR.Format(SR.TarInvalidFormat, Format)), }; await task.ConfigureAwait(false);