You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[release/7.0] Change some exception types thrown in Tar APIs (#74893)
* Throw ArgumentException on unsupported tar entry type
* Adjust tests
* Also change exception type for internal TarEntry conversion constructor called by all other public conversion constructors. Add missing test gap.
* LinkName setter null check.
* Internal constructors SeekableSubReadStream and SubReadStream unseekable exception should be ArgumentException.
* DataStream setter for regular file should throw ArgumentException if passed an unreadable stream.
* TarFile CreateFromDirectory unwritable destination change exception to ArgumentException.
* Change to ArgumentException when ExtractToDirectory is an unreadable stream. Add missing exception docs.
* Add some missing exception docs for TarEntry.
* Change TarReader constructor exception if unreadable stream. Close test gap.
* Change TarWriter exception for unwritable stream to ArgumentException, adjust docs and tests.
* Add missing documentation for exceptions in constructors.
* Change wording of conversion constructors comment when passing a Pax GEA entry.
* Apply suggestions by Jozkee
* Add exception to LinkName if the entry type is hard/symlink and the user tries to set an empty string. Add tests.
* Convert all FormatException to InvalidDataException
* Address more suggestions
Co-authored-by: carlossanlop <[email protected]>
/// <param name="entryType">The type of the entry.</param>
22
22
/// <param name="entryName">A string with the path and file name of this entry.</param>
23
-
/// <exception cref="ArgumentException"><paramref name="entryName"/> is null or empty.</exception>
24
-
/// <exception cref="InvalidOperationException">The entry type is not supported for creating an entry.</exception>
25
23
/// <remarks>When creating an instance using the <see cref="GnuTarEntry(TarEntryType, string)"/> constructor, only the following entry types are supported:
@@ -38,6 +40,9 @@ public GnuTarEntry(TarEntryType entryType, string entryName)
38
40
/// <summary>
39
41
/// Initializes a new <see cref="GnuTarEntry"/> instance by converting the specified <paramref name="other"/> entry into the GNU format.
40
42
/// </summary>
43
+
/// <exception cref="ArgumentException"><para><paramref name="other"/> is a <see cref="PaxGlobalExtendedAttributesTarEntry"/> and cannot be converted.</para>
44
+
/// <para>-or-</para>
45
+
/// <para>The entry type of <paramref name="other"/> is not supported for conversion to the GNU format.</para></exception>
/// <param name="entryType">The type of the entry.</param>
27
27
/// <param name="entryName">A string with the path and file name of this entry.</param>
28
-
/// <exception cref="ArgumentException"><paramref name="entryName"/> is null or empty.</exception>
29
-
/// <exception cref="InvalidOperationException">The entry type is not supported for creating an entry.</exception>
30
28
/// <remarks><para>When creating an instance using the <see cref="PaxTarEntry(TarEntryType, string)"/> constructor, only the following entry types are supported:</para>
@@ -62,9 +64,6 @@ public PaxTarEntry(TarEntryType entryType, string entryName)
62
64
/// <param name="entryType">The type of the entry.</param>
63
65
/// <param name="entryName">A string with the path and file name of this entry.</param>
64
66
/// <param name="extendedAttributes">An enumeration of string key-value pairs that represents the metadata to include in the Extended Attributes entry that precedes the current entry.</param>
65
-
/// <exception cref="ArgumentNullException"><paramref name="extendedAttributes"/> is <see langword="null"/>.</exception>
66
-
/// <exception cref="ArgumentException"><paramref name="entryName"/> is null or empty.</exception>
67
-
/// <exception cref="InvalidOperationException">The entry type is not supported for creating an entry.</exception>
68
67
/// <remarks>When creating an instance using the <see cref="PaxTarEntry(TarEntryType, string)"/> constructor, only the following entry types are supported:
@@ -85,6 +84,10 @@ public PaxTarEntry(TarEntryType entryType, string entryName)
85
84
/// <item>File length, under the name <c>size</c>, as an <see cref="int"/>, if the string representation of the number is larger than 12 bytes.</item>
86
85
/// </list>
87
86
/// </remarks>
87
+
/// <exception cref="ArgumentNullException"><paramref name="extendedAttributes"/> or <paramref name="entryName"/> is <see langword="null"/>.</exception>
88
+
/// <exception cref="ArgumentException"><para><paramref name="entryName"/> is empty.</para>
89
+
/// <para>-or-</para>
90
+
/// <para><paramref name="entryType"/> is not supported in the specified format.</para></exception>
@@ -100,6 +103,9 @@ public PaxTarEntry(TarEntryType entryType, string entryName, IEnumerable<KeyValu
100
103
/// <summary>
101
104
/// Initializes a new <see cref="PaxTarEntry"/> instance by converting the specified <paramref name="other"/> entry into the PAX format.
102
105
/// </summary>
106
+
/// <exception cref="ArgumentException"><para><paramref name="other"/> is a <see cref="PaxGlobalExtendedAttributesTarEntry"/> and cannot be converted.</para>
107
+
/// <para>-or-</para>
108
+
/// <para>The entry type of <paramref name="other"/> is not supported for conversion to the PAX format.</para></exception>
/// A timestamps that represents the last time the contents of the file represented by this entry were modified.
93
93
/// </summary>
94
94
/// <remarks>In Unix platforms, this timestamp is commonly known as <c>mtime</c>.</remarks>
95
+
/// <exception cref="ArgumentOutOfRangeException">The specified value is larger than <see cref="DateTimeOffset.UnixEpoch"/>.</exception>
95
96
publicDateTimeOffsetModificationTime
96
97
{
97
98
get=>_header._mTime;
@@ -114,7 +115,9 @@ public DateTimeOffset ModificationTime
114
115
/// <summary>
115
116
/// When the <see cref="EntryType"/> indicates a <see cref="TarEntryType.SymbolicLink"/> or a <see cref="TarEntryType.HardLink"/>, this property returns the link target path of such link.
116
117
/// </summary>
117
-
/// <exception cref="InvalidOperationException">Cannot set the link name if the entry type is not <see cref="TarEntryType.HardLink"/> or <see cref="TarEntryType.SymbolicLink"/>.</exception>
118
+
/// <exception cref="InvalidOperationException">The entry type is not <see cref="TarEntryType.HardLink"/> or <see cref="TarEntryType.SymbolicLink"/>.</exception>
119
+
/// <exception cref="ArgumentNullException">The specified value is <see langword="null"/>.</exception>
120
+
/// <exception cref="ArgumentException">The specified value is empty.</exception>
/// <para>Elevation is required to extract a <see cref="TarEntryType.BlockDevice"/> or <see cref="TarEntryType.CharacterDevice"/> to disk.</para>
178
182
/// <para>Symbolic links can be recreated using <see cref="File.CreateSymbolicLink(string, string)"/>, <see cref="Directory.CreateSymbolicLink(string, string)"/> or <see cref="FileSystemInfo.CreateAsSymbolicLink(string)"/>.</para>
179
183
/// <para>Hard links can only be extracted when using <see cref="TarFile.ExtractToDirectory(Stream, string, bool)"/> or <see cref="TarFile.ExtractToDirectory(string, string, bool)"/>.</para></remarks>
180
-
/// <exception cref="ArgumentException"><paramref name="destinationFileName"/> is <see langword="null"/> or empty.</exception>
184
+
/// <exception cref="ArgumentNullException"><paramref name="destinationFileName"/> is <see langword="null"/>.</exception>
185
+
/// <exception cref="ArgumentException"><paramref name="destinationFileName"/> is empty.</exception>
181
186
/// <exception cref="IOException"><para>The parent directory of <paramref name="destinationFileName"/> does not exist.</para>
182
187
/// <para>-or-</para>
183
188
/// <para><paramref name="overwrite"/> is <see langword="false"/> and a file already exists in <paramref name="destinationFileName"/>.</para>
@@ -206,7 +211,8 @@ public void ExtractToFile(string destinationFileName, bool overwrite)
206
211
/// <returns>A task that represents the asynchronous extraction operation.</returns>
207
212
/// <remarks><para>Files of type <see cref="TarEntryType.BlockDevice"/>, <see cref="TarEntryType.CharacterDevice"/> or <see cref="TarEntryType.Fifo"/> can only be extracted in Unix platforms.</para>
208
213
/// <para>Elevation is required to extract a <see cref="TarEntryType.BlockDevice"/> or <see cref="TarEntryType.CharacterDevice"/> to disk.</para></remarks>
209
-
/// <exception cref="ArgumentException"><paramref name="destinationFileName"/> is <see langword="null"/> or empty.</exception>
214
+
/// <exception cref="ArgumentNullException"><paramref name="destinationFileName"/> is <see langword="null"/>.</exception>
215
+
/// <exception cref="ArgumentException"><paramref name="destinationFileName"/> is empty.</exception>
210
216
/// <exception cref="IOException"><para>The parent directory of <paramref name="destinationFileName"/> does not exist.</para>
211
217
/// <para>-or-</para>
212
218
/// <para><paramref name="overwrite"/> is <see langword="false"/> and a file already exists in <paramref name="destinationFileName"/>.</para>
/// <para>Sets a new stream that represents the data section, if it makes sense for the <see cref="EntryType"/> to contain data; if a stream already existed, the old stream gets disposed before substituting it with the new stream. Setting a <see langword="null"/> stream is allowed.</para></value>
238
244
/// <remarks>If you write data to this data stream, make sure to rewind it to the desired start position before writing this entry into an archive using <see cref="TarWriter.WriteEntry(TarEntry)"/>.</remarks>
239
245
/// <exception cref="InvalidOperationException">Setting a data section is not supported because the <see cref="EntryType"/> is not <see cref="TarEntryType.RegularFile"/> (or <see cref="TarEntryType.V7RegularFile"/> for an archive of <see cref="TarEntryFormat.V7"/> format).</exception>
240
-
/// <exception cref="IOException"><para>Cannot set an unreadable stream.</para>
241
-
/// <para>-or-</para>
242
-
/// <para>An I/O problem occurred.</para></exception>
246
+
/// <exception cref="ArgumentException">Cannot set an unreadable stream.</exception>
247
+
/// <exception cref="IOException">An I/O problem occurred.</exception>
0 commit comments