Example #1
0
 public TarEntry(TarHeader header)
 {
     if (header == null)
     {
         throw new ArgumentNullException("header");
     }
     this.header = (TarHeader)header.Clone();
 }
Example #2
0
 public void PutNextEntry(TarEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     if (entry.TarHeader.Name.Length >= 100)
     {
         TarHeader header = new TarHeader
         {
             TypeFlag = 0x4c,
             UserId = 0, GroupId = 0,
             GroupName = "",
             UserName = "",
             LinkName = "",
             Size = entry.TarHeader.Name.Length
         };
         header.Name += "././@LongLink";
         header.WriteHeader(blockBuffer);
         buffer.WriteBlock(blockBuffer);
         int nameOffset = 0;
         while (nameOffset < entry.TarHeader.Name.Length)
         {
             Array.Clear(blockBuffer, 0, blockBuffer.Length);
             TarHeader.GetAsciiBytes(entry.TarHeader.Name, nameOffset, blockBuffer, 0, 0x200);
             nameOffset += 0x200;
             buffer.WriteBlock(blockBuffer);
         }
     }
     entry.WriteEntryHeader(blockBuffer);
     buffer.WriteBlock(blockBuffer);
     currBytes = 0L;
     currSize = entry.IsDirectory ? 0L : entry.Size;
 }
Example #3
0
 private TarEntry()
 {
     header = new TarHeader();
 }
Example #4
0
 public void GetFileTarHeader(TarHeader head, string f)
 {
     if (head == null)
     {
         throw new ArgumentNullException("head");
     }
     if (f == null)
     {
         throw new ArgumentNullException("f");
     }
     file = f;
     string str = f;
     if (str.IndexOf(Environment.CurrentDirectory, StringComparison.Ordinal) == 0)
     {
         str = str.Substring(Environment.CurrentDirectory.Length);
     }
     str = str.Replace(Path.DirectorySeparatorChar, '/');
     while (str.StartsWith("/"))
     {
         str = str.Substring(1);
     }
     head.LinkName = string.Empty;
     head.Name = str;
     if (Directory.Exists(f))
     {
         head.Mode = 0x3eb;
         head.TypeFlag = 0x35;
         if ((head.Name.Length == 0) || (head.Name[head.Name.Length - 1] != '/'))
         {
             head.Name = head.Name + "/";
         }
         head.Size = 0L;
     }
     else
     {
         head.Mode = 0x81c0;
         head.TypeFlag = 0x30;
         head.Size = new FileInfo(f.Replace('/', Path.DirectorySeparatorChar)).Length;
     }
     head.ModTime = System.IO.File.GetLastWriteTime(f.Replace('/', Path.DirectorySeparatorChar)).ToUniversalTime();
     head.DevMajor = 0;
     head.DevMinor = 0;
 }
Example #5
0
 public static void NameTarHeader(TarHeader header, string name)
 {
     if (header == null)
     {
         throw new ArgumentNullException("header");
     }
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     bool flag = name.EndsWith("/");
     header.Name = name;
     header.Mode = flag ? 0x3eb : 0x81c0;
     header.UserId = 0;
     header.GroupId = 0;
     header.Size = 0L;
     header.ModTime = DateTime.UtcNow;
     header.TypeFlag = flag ? ((byte)0x35) : ((byte)0x30);
     header.LinkName = string.Empty;
     header.UserName = string.Empty;
     header.GroupName = string.Empty;
     header.DevMajor = 0;
     header.DevMinor = 0;
 }
Example #6
0
 public TarEntry(byte[] headerBuffer)
 {
     header = new TarHeader();
     header.ParseBuffer(headerBuffer);
 }
Example #7
0
 public TarEntry GetNextEntry()
 {
     if (hasHitEOF)
     {
         return null;
     }
     if (currentEntry != null)
     {
         SkipToNextEntry();
     }
     byte[] block = tarBuffer.ReadBlock();
     if (block == null)
     {
         hasHitEOF = true;
     }
     else if (TarBuffer.IsEndOfArchiveBlock(block))
     {
         hasHitEOF = true;
     }
     if (hasHitEOF)
     {
         currentEntry = null;
     }
     else
     {
         try
         {
             TarHeader header = new TarHeader();
             header.ParseBuffer(block);
             if (!header.IsChecksumValid)
             {
                 throw new TarException("Header checksum is invalid");
             }
             entryOffset = 0L;
             entrySize = header.Size;
             StringBuilder builder = null;
             if (header.TypeFlag == 0x4c)
             {
                 byte[] buffer = new byte[0x200];
                 long size = entrySize;
                 builder = new StringBuilder();
                 while (size > 0L)
                 {
                     int length = Read(buffer, 0, (size > buffer.Length) ? buffer.Length : ((int)size));
                     if (length == -1)
                     {
                         throw new InvalidHeaderException("Failed to read long name entry");
                     }
                     builder.Append(TarHeader.ParseName(buffer, 0, length));
                     size -= length;
                 }
                 SkipToNextEntry();
                 block = tarBuffer.ReadBlock();
             }
             else if (header.TypeFlag == 0x67)
             {
                 SkipToNextEntry();
                 block = tarBuffer.ReadBlock();
             }
             else if (header.TypeFlag == 120)
             {
                 SkipToNextEntry();
                 block = tarBuffer.ReadBlock();
             }
             else if (header.TypeFlag == 0x56)
             {
                 SkipToNextEntry();
                 block = tarBuffer.ReadBlock();
             }
             else if (((header.TypeFlag != 0x30) && (header.TypeFlag != 0)) && (header.TypeFlag != 0x35))
             {
                 SkipToNextEntry();
                 block = tarBuffer.ReadBlock();
             }
             if (entryFactory == null)
             {
                 currentEntry = new TarEntry(block);
                 if (builder != null)
                 {
                     currentEntry.Name = builder.ToString();
                 }
             }
             else
             {
                 currentEntry = entryFactory.CreateEntry(block);
             }
             entryOffset = 0L;
             entrySize = currentEntry.Size;
         }
         catch (InvalidHeaderException exception)
         {
             entrySize = 0L;
             entryOffset = 0L;
             currentEntry = null;
             throw new InvalidHeaderException(string.Format("Bad header in record {0} block {1} {2}", tarBuffer.CurrentRecord, tarBuffer.CurrentBlock, exception.Message));
         }
     }
     return currentEntry;
 }