/// <summary>
 /// Add the checksum integer to header buffer.
 /// </summary>
 /// <param name = "value"></param>
 /// <param name = "buffer">The header buffer to set the checksum for</param>
 /// <param name = "offset">The offset into the buffer for the checksum</param>
 /// <param name = "length">The number of header bytes to update.
 /// It's formatted differently from the other fields: it has 6 digits, a
 /// null, then a space -- rather than digits, a space, then a null.
 /// The final space is already there, from checksumming
 /// </param>
 /// <returns>The modified buffer offset</returns>
 static int GetCheckSumOctalBytes(long value, byte[] buffer, int offset, int length)
 {
     TarHeader.GetOctalBytes(value, buffer, offset, length - 1);
     return(offset + length);
 }
Exemple #2
0
 /// <summary>
 /// Construct an entry from an archive's header bytes. File is set
 /// to null.
 /// </summary>
 /// <param name = "headerBuffer">
 /// The header bytes from a tar archive entry.
 /// </param>
 public TarEntry(byte[] headerBuffer)
 {
     header = new TarHeader();
     header.ParseBuffer(headerBuffer);
 }
Exemple #3
0
 /// <summary>
 /// Convenience method that will modify an entry's name directly
 /// in place in an entry header buffer byte array.
 /// </summary>
 /// <param name="buffer">
 /// The buffer containing the entry header to modify.
 /// </param>
 /// <param name="newName">
 /// The new name to place into the header buffer.
 /// </param>
 static public void AdjustEntryName(byte[] buffer, string newName)
 {
     TarHeader.GetNameBytes(newName, buffer, 0, TarHeader.NAMELEN);
 }
Exemple #4
0
 /// <summary>
 /// Initialise a default instance of <see cref="TarEntry"/>.
 /// </summary>
 private TarEntry()
 {
     header = new TarHeader();
 }
Exemple #5
0
        /// <summary>
        /// Fill in a TarHeader with information from a File.
        /// </summary>
        /// <param name="header">
        /// The TarHeader to fill in.
        /// </param>
        /// <param name="file">
        /// The file from which to get the header information.
        /// </param>
        public void GetFileTarHeader(TarHeader header, string file)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            this.file = file;

            // bugfix from torhovl from #D forum:
            string name = file;

#if !NETCF_1_0 && !NETCF_2_0
            // 23-Jan-2004 GnuTar allows device names in path where the name is not local to the current directory
            if (name.IndexOf(Environment.CurrentDirectory) == 0)
            {
                name = name.Substring(Environment.CurrentDirectory.Length);
            }
#endif

/*
 *                      if (Path.DirectorySeparatorChar == '\\')
 *                      {
 *                              // check if the OS is Windows
 *                              // Strip off drive letters!
 *                              if (name.Length > 2)
 *                              {
 *                                      char ch1 = name[0];
 *                                      char ch2 = name[1];
 *
 *                                      if (ch2 == ':' && Char.IsLetter(ch1))
 *                                      {
 *                                              name = name.Substring(2);
 *                                      }
 *                              }
 *                      }
 */

            name = name.Replace(Path.DirectorySeparatorChar, '/');

            // No absolute pathnames
            // Windows (and Posix?) paths can start with UNC style "\\NetworkDrive\",
            // so we loop on starting /'s.
            while (name.StartsWith("/"))
            {
                name = name.Substring(1);
            }

            header.LinkName = String.Empty;
            header.Name     = name;

            if (Directory.Exists(file))
            {
                header.Mode     = 1003;                 // Magic number for security access for a UNIX filesystem
                header.TypeFlag = TarHeader.LF_DIR;
                if ((header.Name.Length == 0) || header.Name[header.Name.Length - 1] != '/')
                {
                    header.Name = header.Name + "/";
                }

                header.Size = 0;
            }
            else
            {
                header.Mode     = 33216;                 // Magic number for security access for a UNIX filesystem
                header.TypeFlag = TarHeader.LF_NORMAL;
                header.Size     = new FileInfo(file.Replace('/', Path.DirectorySeparatorChar)).Length;
            }

            header.ModTime  = System.IO.File.GetLastWriteTime(file.Replace('/', Path.DirectorySeparatorChar)).ToUniversalTime();
            header.DevMajor = 0;
            header.DevMinor = 0;
        }