Extracts a TAR archive.
Inheritance: ArchiveExtractor
Exemplo n.º 1
0
        public void TestExtractUnixArchiveWithHardlink()
        {
            using (var extractor = new TarExtractor(typeof(TarExtractorTest).GetEmbeddedStream("testArchive.tar"), _sandbox))
                extractor.Run();

            FileUtils.AreHardlinked(Path.Combine(_sandbox, "subdir1", "regular"), Path.Combine(_sandbox, "hardlink"))
            .Should().BeTrue(because: "'regular' and 'hardlink' should be hardlinked together");
        }
Exemplo n.º 2
0
        public static Extractor FromStream([NotNull] Stream stream, [NotNull] string target, [CanBeNull] string mimeType)
        {
            #region Sanity checks
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (string.IsNullOrEmpty(target))
            {
                throw new ArgumentNullException("target");
            }
            #endregion

            // Select the correct extractor based on the MIME type
            Extractor extractor;
            switch (mimeType)
            {
            case Model.Archive.MimeTypeZip:
                extractor = new ZipExtractor(stream, target);
                break;

            case Model.Archive.MimeTypeTar:
                extractor = new TarExtractor(stream, target);
                break;

            case Model.Archive.MimeTypeTarGzip:
                extractor = new TarGzExtractor(stream, target);
                break;

            case Model.Archive.MimeTypeTarBzip:
                extractor = new TarBz2Extractor(stream, target);
                break;

            case Model.Archive.MimeTypeTarLzma:
                extractor = new TarLzmaExtractor(stream, target);
                break;

            case Model.Archive.MimeTypeRubyGem:
                extractor = new RubyGemExtractor(stream, target);
                break;

            case Model.Archive.MimeType7Z:
                extractor = new SevenZipExtractor(stream, target);
                break;

            case Model.Archive.MimeTypeCab:
                extractor = new CabExtractor(stream, target);
                break;

            case Model.Archive.MimeTypeMsi:
                throw new NotSupportedException("MSIs can only be accessed as local files, not as streams!");

            default:
                throw new NotSupportedException(string.Format(Resources.UnsupportedArchiveMimeType, mimeType));
            }

            return(extractor);
        }
Exemplo n.º 3
0
        public void TestExtractUnixArchiveWithExecutable()
        {
            using (var extractor = new TarExtractor(typeof(TarExtractorTest).GetEmbeddedStream("testArchive.tar"), _sandbox))
                extractor.Run();

            if (UnixUtils.IsUnix)
            {
                FileUtils.IsExecutable(Path.Combine(_sandbox, "subdir2/executable")).Should().BeTrue(because: "File 'executable' should be marked as executable");
            }
            else
            {
                string xbitFileContent = File.ReadAllText(Path.Combine(_sandbox, FlagUtils.XbitFile)).Trim();
                xbitFileContent.Should().Be("/subdir2/executable");
            }
        }
Exemplo n.º 4
0
        public void TestExtractUnixArchiveWithExecutable()
        {
            using (var stream = typeof(ExtractorTest).GetEmbeddedStream("testArchive.tar"))
                using (var extractor = new TarExtractor(stream, _sandbox))
                    extractor.Run();

            if (UnixUtils.IsUnix)
            {
                Assert.IsTrue(FileUtils.IsExecutable(Path.Combine(_sandbox, "subdir2/executable")), "File 'executable' should be marked as executable");
            }
            else
            {
                string xbitFileContent = File.ReadAllText(Path.Combine(_sandbox, FlagUtils.XbitFile)).Trim();
                Assert.AreEqual("/subdir2/executable", xbitFileContent);
            }
        }
Exemplo n.º 5
0
        public void TestExtractUnixArchiveWithSymlink()
        {
            using (var extractor = new TarExtractor(typeof(TarExtractorTest).GetEmbeddedStream("testArchive.tar"), _sandbox))
                extractor.Run();

            string target;
            string source = Path.Combine(_sandbox, "symlink");

            if (UnixUtils.IsUnix)
            {
                FileUtils.IsSymlink(source, out target).Should().BeTrue();
            }
            else
            {
                CygwinUtils.IsSymlink(source, out target).Should().BeTrue();
            }

            target.Should().Be("subdir1/regular", because: "Symlink should point to 'regular'");
        }
Exemplo n.º 6
0
        public void TestExtractUnixArchiveWithSymlink()
        {
            using (var stream = typeof(ExtractorTest).GetEmbeddedStream("testArchive.tar"))
                using (var extractor = new TarExtractor(stream, _sandbox))
                    extractor.Run();

            string target;

            if (UnixUtils.IsUnix)
            {
                Assert.IsTrue(FileUtils.IsSymlink(Path.Combine(_sandbox, "symlink"), out target));
            }
            else
            {
                string symlinkFileContent = File.ReadAllText(Path.Combine(_sandbox, FlagUtils.SymlinkFile)).Trim();
                Assert.AreEqual("/symlink", symlinkFileContent);
                target = File.ReadAllText(Path.Combine(_sandbox, "symlink"));
            }
            Assert.AreEqual("subdir1/regular", target, "Symlink should point to 'regular'");
        }
Exemplo n.º 7
0
        public void TestExtractUnixArchiveWithSymlink()
        {
            using (var extractor = new TarExtractor(this.GetEmbedded("testArchive.tar"), _sandbox))
                extractor.Run();

            string target;
            if (UnixUtils.IsUnix)
                Assert.IsTrue(FileUtils.IsSymlink(Path.Combine(_sandbox, "symlink"), out target));
            else
            {
                string symlinkFileContent = File.ReadAllText(Path.Combine(_sandbox, FlagUtils.SymlinkFile)).Trim();
                Assert.AreEqual("/symlink", symlinkFileContent);
                target = File.ReadAllText(Path.Combine(_sandbox, "symlink"));
            }
            Assert.AreEqual("subdir1/regular", target, "Symlink should point to 'regular'");
        }
Exemplo n.º 8
0
        public void TestExtractUnixArchiveWithHardlink()
        {
            using (var extractor = new TarExtractor(this.GetEmbedded("testArchive.tar"), _sandbox))
                extractor.Run();

            Assert.IsTrue(
                FileUtils.AreHardlinked(Path.Combine(_sandbox, "subdir1", "regular"), Path.Combine(_sandbox, "hardlink")),
                "'regular' and 'hardlink' should be hardlinked together");
        }
Exemplo n.º 9
0
        public void TestExtractUnixArchiveWithExecutable()
        {
            using (var extractor = new TarExtractor(this.GetEmbedded("testArchive.tar"), _sandbox))
                extractor.Run();

            if (UnixUtils.IsUnix)
                Assert.IsTrue(FileUtils.IsExecutable(Path.Combine(_sandbox, "subdir2/executable")), "File 'executable' should be marked as executable");
            else
            {
                string xbitFileContent = File.ReadAllText(Path.Combine(_sandbox, FlagUtils.XbitFile)).Trim();
                Assert.AreEqual("/subdir2/executable", xbitFileContent);
            }
        }
Exemplo n.º 10
0
        public static ArchiveExtractor Create([NotNull] Stream stream, [NotNull] string target, [CanBeNull] string mimeType)
        {
            #region Sanity checks
            if (stream == null) throw new ArgumentNullException(nameof(stream));
            if (string.IsNullOrEmpty(target)) throw new ArgumentNullException(nameof(target));
            #endregion

            ArchiveExtractor extractor;
            switch (mimeType)
            {
                case Archive.MimeTypeZip:
                    extractor = new ZipExtractor(stream, target);
                    break;
                case Archive.MimeTypeTar:
                    extractor = new TarExtractor(stream, target);
                    break;
                case Archive.MimeTypeTarGzip:
                    extractor = new TarGzExtractor(stream, target);
                    break;
                case Archive.MimeTypeTarBzip:
                    extractor = new TarBz2Extractor(stream, target);
                    break;
                case Archive.MimeTypeTarLzma:
                    extractor = new TarLzmaExtractor(stream, target);
                    break;
                case Archive.MimeTypeTarXz:
                    extractor = new TarXzExtractor(stream, target);
                    break;
                case Archive.MimeTypeRubyGem:
                    extractor = new RubyGemExtractor(stream, target);
                    break;
                case Archive.MimeType7Z:
                    extractor = new SevenZipExtractor(stream, target);
                    break;
                case Archive.MimeTypeCab:
                    extractor = new CabExtractor(stream, target);
                    break;
                case Archive.MimeTypeMsi:
                    throw new NotSupportedException("MSIs can only be accessed as local files, not as streams!");
                default:
                    throw new NotSupportedException(string.Format(Resources.UnsupportedArchiveMimeType, mimeType));
            }

            return extractor;
        }
Exemplo n.º 11
0
        public void TestExtractUnixArchiveWithHardlink()
        {
            using (var extractor = new TarExtractor(typeof(TarExtractorTest).GetEmbeddedStream("testArchive.tar"), _sandbox))
                extractor.Run();

            FileUtils.AreHardlinked(Path.Combine(_sandbox, "subdir1", "regular"), Path.Combine(_sandbox, "hardlink"))
                .Should().BeTrue(because: "'regular' and 'hardlink' should be hardlinked together");
        }
Exemplo n.º 12
0
        public void TestExtractUnixArchiveWithSymlink()
        {
            using (var extractor = new TarExtractor(typeof(TarExtractorTest).GetEmbeddedStream("testArchive.tar"), _sandbox))
                extractor.Run();

            string target;
            string source = Path.Combine(_sandbox, "symlink");
            if (UnixUtils.IsUnix) FileUtils.IsSymlink(source, out target).Should().BeTrue();
            else CygwinUtils.IsSymlink(source, out target).Should().BeTrue();

            target.Should().Be("subdir1/regular", because: "Symlink should point to 'regular'");
        }
Exemplo n.º 13
0
        public void TestExtractUnixArchiveWithExecutable()
        {
            using (var extractor = new TarExtractor(typeof(TarExtractorTest).GetEmbeddedStream("testArchive.tar"), _sandbox))
                extractor.Run();

            if (UnixUtils.IsUnix)
                FileUtils.IsExecutable(Path.Combine(_sandbox, "subdir2/executable")).Should().BeTrue(because: "File 'executable' should be marked as executable");
            else
            {
                string xbitFileContent = File.ReadAllText(Path.Combine(_sandbox, FlagUtils.XbitFile)).Trim();
                xbitFileContent.Should().Be("/subdir2/executable");
            }
        }