Skip to content

Commit d28041d

Browse files
authored
Merge pull request #170 from dotnet-campus/t/lindexi/TarHeader
添加更多考古注释内容
2 parents fc64883 + fd65286 commit d28041d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

DebUOS/Packaging.Targets/IO/TarHeader.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ internal unsafe struct TarHeader : IArchiveHeader
6868
public string FileName
6969
{
7070
get => this.GetString(this.name, 100);
71-
set => this.name = this.CreateString(value, 100);
71+
set => this.name = this.CreateString(value, 100, reason: TarLimitReason);
7272
}
7373

74+
private const string TarLimitReason = "From http://ibgwww.colorado.edu/~lessem/psyc5112/usail/man/solaris/tar.1.html , The file name (or leaf) length cannot exceed 100 characters. It is the limit of tar.";
75+
7476
public LinuxFileMode FileMode
7577
{
7678
get => (LinuxFileMode)Convert.ToUInt32(this.GetString(this.mode, 8), 8);
@@ -124,7 +126,7 @@ public TarTypeFlag TypeFlag
124126
public string LinkName
125127
{
126128
get => this.GetString(this.linkname, 100);
127-
set => this.linkname = this.CreateString(value, 100);
129+
set => this.linkname = this.CreateString(value, 100, TarLimitReason);
128130
}
129131

130132
public string Magic
@@ -242,7 +244,8 @@ private byte[] GetUIntTo8(uint? data, int len = 8)
242244
return this.CreateString(Convert.ToString(data.Value, 8).PadLeft(len - 1, '0'), len);
243245
}
244246

245-
private byte[] CreateString(string s, int len)
247+
#nullable enable
248+
private byte[] CreateString(string? s, int len, string? reason = null)
246249
{
247250
var target = new byte[len];
248251
if (s == null)
@@ -253,7 +256,7 @@ private byte[] CreateString(string s, int len)
253256
var buffer = Encoding.UTF8.GetBytes(s);
254257
if (buffer.Length > len)
255258
{
256-
throw new Exception($"String {s} exceeds the limit of {len}");
259+
throw new Exception($"String {s} exceeds the limit of {len}.{reason}");
257260
}
258261

259262
for (var c = 0; c < len; c++)

0 commit comments

Comments
 (0)