コード例 #1
0
        public bool TryPutTime(DateTime time, TarHeader.HeaderField field)
        {
            uint nanoseconds = 0;
            long unixTime    = 0;

            if (time.Ticks != 0)
            {
                unixTime = TarTime.ToUnixTime(time, out nanoseconds);
            }

            if (TryPutOctal(unixTime, field.WithoutPax) && nanoseconds == 0)
            {
                return(true);
            }

            if (field.PaxAttribute != null && PaxAttributes != null)
            {
                PaxAttributes[field.PaxAttribute] = TarTime.ToPaxTime(time);
            }

            return(false);
        }
コード例 #2
0
ファイル: TarWriter.cs プロジェクト: zanssa/Docker-PowerShell
        private static void GenerateHeader(ref TarHeaderView header, TarEntry entry, ArraySegment <byte> name)
        {
            var needsPath = false;

            header.PutNul(TarHeader.FullHeader);

            // Try to write the name, but don't write the PAX attribute yet in case we can
            // just write a split name later.
            if (name.Count > 0)
            {
                header.PutBytes(name, TarHeader.Name);
            }
            else if (!header.TryPutString(entry.Name, TarHeader.Name.WithoutPax))
            {
                needsPath = true;
            }

            header.TryPutOctal(entry.Mode, TarHeader.Mode);
            header.TryPutOctal(entry.UserID, TarHeader.UserID);
            header.TryPutOctal(entry.GroupID, TarHeader.GroupID);
            header.TryPutOctal(entry.Length, TarHeader.Length);
            header.TryPutTime(entry.ModifiedTime, TarHeader.ModifiedTime);

            header[TarHeader.ChecksumSpace.Offset] = (byte)' ';

            header[TarHeader.TypeFlag.Offset] = (byte)entry.Type;

            header.TryPutString(entry.LinkTarget, TarHeader.LinkTarget);

            header.TryPutString(TarCommon.PosixMagic, TarHeader.Magic);
            header[TarHeader.Version.Offset]     = (byte)'0';
            header[TarHeader.Version.Offset + 1] = (byte)'0';

            header.TryPutString(entry.UserName, TarHeader.UserName);
            header.TryPutString(entry.GroupName, TarHeader.GroupName);
            header.TryPutOctal(entry.DeviceMajor, TarHeader.DeviceMajor);
            header.TryPutOctal(entry.DeviceMinor, TarHeader.DeviceMinor);

            if (header.PaxAttributes != null)
            {
                if (entry.AccessTime.HasValue)
                {
                    header.PaxAttributes[TarCommon.PaxAtime] = TarTime.ToPaxTime(entry.AccessTime.Value);
                }

                if (entry.ChangeTime.HasValue)
                {
                    header.PaxAttributes[TarCommon.PaxCtime] = TarTime.ToPaxTime(entry.ChangeTime.Value);
                }

                if (entry.CreationTime.HasValue)
                {
                    header.PaxAttributes[TarCommon.PaxCreationTime] = TarTime.ToPaxTime(entry.CreationTime.Value);
                }

                if (entry.FileAttributes.HasValue)
                {
                    header.PaxAttributes[TarCommon.PaxWindowsFileAttributes] = Convert.ToString((uint)entry.FileAttributes.Value);
                }

                if (entry.IsMountPoint)
                {
                    header.PaxAttributes[TarCommon.PaxWindowsMountPoint] = "1";
                }

                if (entry.SecurityDescriptor != null)
                {
                    header.PaxAttributes[TarCommon.PaxWindowsSecurityDescriptor] = entry.SecurityDescriptor;
                }

                if (needsPath)
                {
                    int splitIndex;
                    if (header.PaxAttributes.Count == 0 && TrySplitPath(entry.Name, out splitIndex))
                    {
                        header.TryPutString(entry.Name.Substring(0, splitIndex), TarHeader.Prefix);
                        header.TryPutString(entry.Name.Substring(splitIndex + 1), TarHeader.Name);
                    }
                    else
                    {
                        header.PaxAttributes[TarHeader.Name.PaxAttribute] = entry.Name;
                    }
                }
            }

            int signedChecksum;
            var checksum = TarCommon.Checksum(header.Field(TarHeader.FullHeader), out signedChecksum);

            header.TryPutOctal(checksum, TarHeader.Checksum);
        }