Exemplo n.º 1
0
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is InternalWriteArchiveEntry))
            {
                return(false);
            }

            InternalWriteArchiveEntry entry = obj as InternalWriteArchiveEntry;

            return(entry.FileName.Compare(FileName) &&
                   entry.INode == entry.INode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get writer for the archive entry
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        public static IArchiveEntryWriter GetWriter(InternalWriteArchiveEntry entry, IReadableCPIOArchiveEntry readableEntry)
        {
            switch (entry.ArchiveType)
            {
            case ArchiveEntryType.DIRECTORY:
                return(new DirectoryEntryWriter(entry, readableEntry));

            case ArchiveEntryType.FILE:
                if (entry.nLink > 1)
                {
                    return(new HardLinkEntryWriter(entry, readableEntry));
                }
                else
                {
                    return(new FileEntryWriter(entry, readableEntry));
                }

            case ArchiveEntryType.SYMBOLIC_LINK:
                return(new SymbolicLinkEntryWriter(entry, readableEntry));

            default:
                throw new Exception("Нет класса, реализующего запись для данного типа");
            }
        }
        public override void ReadMetadataEntry()
        {
            unsafe
            {
                byte[] majorBuffer;
                byte[] minorBuffer;
                // Dev
                fixed(byte *pointer = _entry.c_devmajor)
                {
                    majorBuffer = GetByteArrayFromFixedArray(pointer, 8);
                }

                fixed(byte *pointer = _entry.c_devminor)
                {
                    minorBuffer = GetByteArrayFromFixedArray(pointer, 8);
                }

                _archiveEntry.Dev = GetValueFromHexValue(majorBuffer).ToString() + GetValueFromHexValue(minorBuffer).ToString();

                // Ino
                fixed(byte *pointer = _entry.c_ino)
                {
                    majorBuffer = GetByteArrayFromFixedArray(pointer, 8);
                }

                _archiveEntry.INode = GetValueFromHexValue(majorBuffer).ToString();

                // Type, Permission
                fixed(byte *pointer = _entry.c_mode)
                {
                    majorBuffer = GetByteArrayFromFixedArray(pointer, 8);
                }

                long mode = GetValueFromHexValue(majorBuffer);
                _archiveEntry.ArchiveType = InternalWriteArchiveEntry.GetArchiveEntryType(mode);
                _archiveEntry.Permission  = InternalWriteArchiveEntry.GetPermission(mode);

                // Uid
                fixed(byte *pointer = _entry.c_uid)
                {
                    majorBuffer = GetByteArrayFromFixedArray(pointer, 8);
                }

                _archiveEntry.Uid = (int)GetValueFromHexValue(majorBuffer);

                // Gid
                fixed(byte *pointer = _entry.c_gid)
                {
                    majorBuffer = GetByteArrayFromFixedArray(pointer, 8);
                }

                _archiveEntry.Gid = (int)GetValueFromHexValue(majorBuffer);

                // mTime
                fixed(byte *pointer = _entry.c_mtime)
                {
                    majorBuffer = GetByteArrayFromFixedArray(pointer, 8);
                }

                _archiveEntry.mTime = GetValueFromHexValue(majorBuffer).ToUnixTime();

                // nLink
                fixed(byte *pointer = _entry.c_nlink)
                {
                    majorBuffer = GetByteArrayFromFixedArray(pointer, 8);
                }

                _archiveEntry.nLink = GetValueFromHexValue(majorBuffer);

                // rDev
                fixed(byte *pointer = _entry.c_rdevmajor)
                {
                    majorBuffer = GetByteArrayFromFixedArray(pointer, 8);
                }

                fixed(byte *pointer = _entry.c_rdevminor)
                {
                    minorBuffer = GetByteArrayFromFixedArray(pointer, 8);
                }

                _archiveEntry.rDev = (int)GetValueFromHexValue(majorBuffer) + (int)GetValueFromHexValue(minorBuffer);

                _archiveEntry.ExtractFlags = _extractFlags;
            }
        }
        /*
         * /// <summary>
         * /// Post extract entry
         * /// </summary>
         * /// <param name="destFolder"></param>
         * /// <param name="archiveEntries"></param>
         * /// <returns></returns>
         * public bool PostExtractEntryToDisk(string destFolder, List<IReaderCPIOArchiveEntry> archiveEntries)
         * {
         *  if (_archiveEntry.nLink > 0 && !_archiveEntry.IsExtractToDisk)
         *  {
         *      IArchiveEntryWriter writer = InternalWriteArchiveEntry.GetWriter(_archiveEntry);
         *      if (writer.IsPostExtractEntry(_archiveEntry))
         *      {
         *          // check is hardlinkfile
         *          if (_archiveEntry.ArchiveType == ArchiveEntryType.FILE && _archiveEntry.nLink > 1)
         *          {
         *              var hardLinkFiles = archiveEntries.Where(a => a.InternalEntry.INode == _archiveEntry.INode);
         *              return ExtractHardlinkFiles(destFolder, hardLinkFiles.ToList());
         *          }
         *          _archiveEntry.IsExtractToDisk = true;
         *          return writer.Write(_archiveEntry, destFolder);
         *      }
         *  }
         *  return true;
         * }
         */

        /// <summary>
        /// Is a entry has name is TRAILER?
        /// </summary>
        /// <returns></returns>
        public bool IsLastArchiveEntry()
        {
            return(InternalWriteArchiveEntry.GetFileName(_archiveEntry.FileName).Equals(CpioStructDefinition.LAST_ARCHIVEENTRY_FILENAME));
        }
        public static IWriterEntry GetWriter(InternalWriteArchiveEntry _entry)
        {
            switch (_entry.ArchiveType)
            {
                case ArchiveEntryType.DIRECTORY:
                    return new DirectoryWriterEntry();

                case ArchiveEntryType.FILE:
                    if (_entry.nLink > 1)
                    {
                        return new HardLinkFileWriterEntry();
                    }
                    else
                    {
                        return new FileWriterEntry();
                    }
                case ArchiveEntryType.SYMBOLIC_LINK:
                    return new SymbolicLinkFileWriterEntry();

                default:
                    throw new Exception("Нет класса, реализующего запись для данного типа");
            }
        }