public DateTime GetTime(TarHeader.HeaderField field) { string paxValue = GetPaxValue(field.PaxAttribute); if (paxValue != null) { return(TarTime.FromPaxTime(paxValue)); } long unixTime = GetOctalLong(field.WithoutPax); if (unixTime < TarTime.MinUnixTime) { unixTime = TarTime.MinUnixTime; } else if (unixTime > TarTime.MaxUnixTime) { unixTime = TarTime.MaxUnixTime; } return(TarTime.FromUnixTime(unixTime, 0)); }
private static TarEntry ParseHeader(ref TarHeaderView header) { var entry = new TarEntry { Name = header.GetString(TarHeader.Name), Mode = header.GetOctal(TarHeader.Mode), UserID = header.GetOctal(TarHeader.UserID), GroupID = header.GetOctal(TarHeader.GroupID), Length = header.GetOctalLong(TarHeader.Length), ModifiedTime = header.GetTime(TarHeader.ModifiedTime) }; var checksum = header.GetOctal(TarHeader.Checksum); int signedChecksum; var unsignedChecksum = TarCommon.Checksum(header.Field(TarHeader.FullHeader), out signedChecksum); if (checksum != signedChecksum && checksum != unsignedChecksum) { throw new TarParseException("invalid tar checksum"); } var typeFlag = header[TarHeader.TypeFlag.Offset]; if (typeFlag == 0) { typeFlag = (byte)'0'; } entry.Type = (TarEntryType)typeFlag; entry.LinkTarget = header.GetString(TarHeader.LinkTarget); var magic = header.GetString(TarHeader.FullMagic); if (magic == TarCommon.PosixMagic || magic == TarCommon.GnuMagic) { entry.UserName = header.GetString(TarHeader.UserName); entry.GroupName = header.GetString(TarHeader.GroupName); entry.DeviceMajor = header.GetOctal(TarHeader.DeviceMajor); entry.DeviceMinor = header.GetOctal(TarHeader.DeviceMinor); if (magic == TarCommon.PosixMagic) { if (header.PaxAttributes == null || !header.PaxAttributes.ContainsKey(TarHeader.Name.PaxAttribute)) { var prefix = header.GetString(TarHeader.Prefix); if (prefix.Length > 0) { entry.Name = prefix + "/" + entry.Name; } } string atime = header.GetPaxValue(TarCommon.PaxAtime); if (atime != null) { entry.AccessTime = TarTime.FromPaxTime(atime); } string ctime = header.GetPaxValue(TarCommon.PaxCtime); if (ctime != null) { entry.ChangeTime = TarTime.FromPaxTime(ctime); } string creationtime = header.GetPaxValue(TarCommon.PaxCreationTime); if (creationtime != null) { entry.CreationTime = TarTime.FromPaxTime(creationtime); } string fileAttributes = header.GetPaxValue(TarCommon.PaxWindowsFileAttributes); if (fileAttributes != null) { entry.FileAttributes = (FileAttributes)Convert.ToUInt32(fileAttributes); } entry.SecurityDescriptor = header.GetPaxValue(TarCommon.PaxWindowsSecurityDescriptor); if (header.GetPaxValue(TarCommon.PaxWindowsMountPoint) != null) { entry.IsMountPoint = true; } } } return(entry); }