Example #1
0
        /// <summary>
        ///     Writes a long name entry to the archive.
        /// </summary>
        /// <param name="name">The long name.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="name" /> is null.</exception>
        private void WriteLongNameEntry(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            name = PathHelper.TarNormalize(name);

            var header = new TarHeader
            {
                Name = "././@LongLink",          // Is supposed to say LongLink, even if it's a long name
                Mode = new FileModeGroup("644"), // Seems to be the default for long links?
                Size = name.Length + 1,
                Flag = TarHeaderFlag.LongName
            };

            // Write the header.
            WriteHeader(header);

            // Write the content.
            var length = _stream.Write(name, name.Length + 1);

            WritePadding(length);
        }
Example #2
0
        /// <summary>
        ///     Writes a tar header for a file entry to the output stream.
        /// </summary>
        /// <param name="path">The path to the file in the archive.</param>
        /// <param name="size">The size of the file.</param>
        /// <param name="lastModification">The last modification date in UTC of the file.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="groupId">The group identifier.</param>
        /// <param name="fileMode">The file mode.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="path" /> is null.</exception>
        public void WriteFileEntry(string path, long size, DateTime lastModification, string userId, string groupId, IFileModeGroup fileMode)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            AssertNotDisposed();

            path = PathHelper.TarNormalize(path);

            if (path.Length >= 100)
            {
                WriteLongNameEntry(path);

                // NOTE: GNU tar puts 100 characters into the name field, without
                // the null terminator. However, the GNU tar specifications state
                // the name should end with a null terminator. Sticking to the
                // specifications here.
                path = path.Substring(0, 99);
            }

            var header = new TarHeader
            {
                Name             = path,
                Mode             = fileMode,
                Size             = size,
                Flag             = TarHeaderFlag.NormalFileAlt,
                UserId           = userId,
                GroupId          = groupId,
                LastModification = lastModification
            };

            WriteHeader(header);
        }