Exemplo n.º 1
0
        /// <summary>
        /// Creates the metadata for all files in the <see cref="CpioFile"/>.
        /// </summary>
        /// <param name="archiveEntries">
        /// The archive entries for which to generate the metadata.
        /// </param>
        /// <returns>
        /// A <see cref="Collection{RpmFile}"/> which contains all the metadata.
        /// </returns>
        public Collection <RpmFile> CreateFiles(List <ArchiveEntry> archiveEntries)
        {
            Collection <RpmFile> files = new Collection <RpmFile>();

            foreach (var entry in archiveEntries)
            {
                var size = entry.FileSize;

                if (entry.Mode.HasFlag(LinuxFileMode.S_IFDIR))
                {
                    size = 0x1000;
                }

                if (entry.Mode.HasFlag(LinuxFileMode.S_IFLNK))
                {
                    // RPM uses cpio archives. cpio archives store the target of a symlink as
                    // the file content (as opposed to tar, which has a dedicated field for this).
                    // As a result, the file size is equal to the length of the path of the link
                    // target.
                    // https://bugzilla.redhat.com/show_bug.cgi?id=1224555 has some background info.
                    size = (uint)Encoding.UTF8.GetByteCount(entry.LinkTo);
                }

                RpmFile file = new RpmFile()
                {
                    Size         = (int)size,
                    Mode         = entry.Mode,
                    Rdev         = 0,
                    ModifiedTime = entry.Modified,
                    MD5Hash      = entry.Sha256, // Yes, the MD5 hash does not actually contain a MD5 hash
                    LinkTo       = entry.LinkTo,
                    Flags        = this.analyzer.DetermineFlags(entry),
                    UserName     = entry.Owner,
                    GroupName    = entry.Group,
                    VerifyFlags  = RpmVerifyFlags.RPMVERIFY_ALL,
                    Device       = 1,
                    Inode        = (int)entry.Inode,
                    Lang         = string.Empty,
                    Color        = this.analyzer.DetermineColor(entry),
                    Class        = this.analyzer.DetermineClass(entry),
                    Requires     = this.analyzer.DetermineRequires(entry),
                    Provides     = this.analyzer.DetermineProvides(entry),
                    Name         = entry.TargetPath
                };

                files.Add(file);
            }

            return(files);
        }
        /// <summary>
        /// Creates the metadata for all files in the <see cref="CpioFile"/>.
        /// </summary>
        /// <param name="archiveEntries">
        /// The archive entries for which to generate the metadata.
        /// </param>
        /// <returns>
        /// A <see cref="Collection{RpmFile}"/> which contains all the metadata.
        /// </returns>
        public Collection <RpmFile> CreateFiles(List <ArchiveEntry> archiveEntries)
        {
            Collection <RpmFile> files = new Collection <RpmFile>();

            foreach (var entry in archiveEntries)
            {
                var size = entry.FileSize;

                if (entry.Mode.HasFlag(LinuxFileMode.S_IFDIR))
                {
                    size = 0x1000;
                }

                RpmFile file = new RpmFile()
                {
                    Size         = (int)size,
                    Mode         = entry.Mode,
                    Rdev         = 0,
                    ModifiedTime = entry.Modified,
                    MD5Hash      = entry.Sha256, // Yes, the MD5 hash does not actually contain a MD5 hash
                    LinkTo       = entry.LinkTo,
                    Flags        = this.analyzer.DetermineFlags(entry),
                    UserName     = entry.Owner,
                    GroupName    = entry.Group,
                    VerifyFlags  = RpmVerifyFlags.RPMVERIFY_ALL,
                    Device       = 1,
                    Inode        = (int)entry.Inode,
                    Lang         = string.Empty,
                    Color        = this.analyzer.DetermineColor(entry),
                    Class        = this.analyzer.DetermineClass(entry),
                    Requires     = this.analyzer.DetermineRequires(entry),
                    Provides     = this.analyzer.DetermineProvides(entry),
                    Name         = entry.TargetPath
                };

                files.Add(file);
            }

            return(files);
        }