mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-16 13:55:11 +00:00
TAR model cleanup
This commit is contained in:
@@ -5,6 +5,6 @@ namespace SabreTools.Data.Models.TAR
|
||||
/// <summary>
|
||||
/// 1 or more entries
|
||||
/// </summary>
|
||||
public Entry[]? Entries { get; set; }
|
||||
public Entry[] Entries { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ namespace SabreTools.Data.Models.TAR
|
||||
|
||||
public const string UstarSignatureString = "ustar";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ namespace SabreTools.Data.Models.TAR
|
||||
/// <summary>
|
||||
/// Entry header
|
||||
/// </summary>
|
||||
public Header? Header { get; set; }
|
||||
public Header Header { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 0 or more blocks representing the content
|
||||
/// </summary>
|
||||
public Block[]? Blocks { get; set; }
|
||||
public Block[] Blocks { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,4 +154,4 @@ namespace SabreTools.Data.Models.TAR
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace SabreTools.Data.Models.TAR
|
||||
{
|
||||
/// <see href="https://www.ibm.com/docs/en/aix/7.3?topic=files-tarh-file"/>
|
||||
/// <see href="https://www.ibm.com/docs/en/aix/7.3?topic=files-tarh-file"/>
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public sealed class Header
|
||||
{
|
||||
@@ -10,49 +10,49 @@ namespace SabreTools.Data.Models.TAR
|
||||
/// File name without a forward slash
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
|
||||
public string? FileName;
|
||||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// File mode
|
||||
/// </summary>
|
||||
/// <remarks>Octal string representation</remarks>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
|
||||
public string? Mode;
|
||||
public string Mode;
|
||||
|
||||
/// <summary>
|
||||
/// Owner's numeric user ID
|
||||
/// </summary>
|
||||
/// <remarks>Octal string representation</remarks>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
|
||||
public string? UID;
|
||||
public string UID;
|
||||
|
||||
/// <summary>
|
||||
/// Owner's numeric group ID
|
||||
/// </summary>
|
||||
/// <remarks>Octal string representation</remarks>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
|
||||
public string? GID;
|
||||
public string GID;
|
||||
|
||||
/// <summary>
|
||||
/// File size in bytes
|
||||
/// </summary>
|
||||
/// <remarks>Octal string representation</remarks>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 12)]
|
||||
public string? Size;
|
||||
public string Size;
|
||||
|
||||
/// <summary>
|
||||
/// Last modification time in numeric Unix time format
|
||||
/// </summary>
|
||||
/// <remarks>Octal string representation</remarks>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 12)]
|
||||
public string? ModifiedTime;
|
||||
public string ModifiedTime;
|
||||
|
||||
/// <summary>
|
||||
/// Checksum for header record
|
||||
/// </summary>
|
||||
/// <remarks>Octal string representation</remarks>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
|
||||
public string? Checksum;
|
||||
public string Checksum;
|
||||
|
||||
/// <summary>
|
||||
/// Link indicator (file type) / Type flag
|
||||
@@ -63,7 +63,7 @@ namespace SabreTools.Data.Models.TAR
|
||||
/// Linked path name or file name
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
|
||||
public string? LinkName;
|
||||
public string LinkName;
|
||||
|
||||
#region USTAR Extension
|
||||
|
||||
@@ -114,4 +114,4 @@ namespace SabreTools.Data.Models.TAR
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
public bool Extract(string outputDirectory, bool includeDebug)
|
||||
{
|
||||
// Ensure there are entries to extract
|
||||
if (Entries == null || Entries.Length == 0)
|
||||
if (Entries.Length == 0)
|
||||
return false;
|
||||
|
||||
try
|
||||
@@ -19,11 +19,6 @@ namespace SabreTools.Serialization.Wrappers
|
||||
for (int i = 0; i < Entries.Length; i++)
|
||||
{
|
||||
var entry = Entries[i];
|
||||
if (entry.Header == null)
|
||||
{
|
||||
if (includeDebug) Console.Error.WriteLine($"Invalid entry {i} found! Skipping...");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle special entries
|
||||
var header = entry.Header;
|
||||
@@ -91,13 +86,6 @@ namespace SabreTools.Serialization.Wrappers
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ensure there are blocks to extract
|
||||
if (entry.Blocks == null)
|
||||
{
|
||||
if (includeDebug) Console.WriteLine($"Entry {i} had no block data");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the file size
|
||||
string sizeOctalString = header.Size!.TrimEnd('\0');
|
||||
if (sizeOctalString.Length == 0)
|
||||
|
||||
@@ -43,18 +43,10 @@ namespace SabreTools.Serialization.Wrappers
|
||||
}
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, Header? header)
|
||||
private static void Print(StringBuilder builder, Header header)
|
||||
{
|
||||
builder.AppendLine(" Header:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
|
||||
if (header == null)
|
||||
{
|
||||
builder.AppendLine(" No header");
|
||||
builder.AppendLine();
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendLine(header.FileName?.TrimEnd('\0'), " File name");
|
||||
builder.AppendLine(header.Mode, " Mode");
|
||||
builder.AppendLine(header.UID, " UID");
|
||||
@@ -74,11 +66,11 @@ namespace SabreTools.Serialization.Wrappers
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
private static void Print(StringBuilder builder, Block[]? entries)
|
||||
private static void Print(StringBuilder builder, Block[] entries)
|
||||
{
|
||||
builder.AppendLine(" Blocks:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
if (entries == null || entries.Length == 0)
|
||||
if (entries.Length == 0)
|
||||
{
|
||||
builder.AppendLine(" No blocks");
|
||||
builder.AppendLine();
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
#region Extension Properties
|
||||
|
||||
/// <inheritdoc cref="Archive.Entries"/>
|
||||
public Entry[]? Entries => Model.Entries;
|
||||
public Entry[] Entries => Model.Entries;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user