public void TestHardlink()
        {
            using (var stream = typeof(ExtractorTest).GetEmbeddedStream("testArchiveHardlink.tar"))
                using (var extractor = Extractor.FromStream(stream, _sandbox, Model.Archive.MimeTypeTar))
                    extractor.Run();

            Assert.AreEqual("data", File.ReadAllText("file1"));
            Assert.AreEqual("data", File.ReadAllText("file2"));
        }
        public void ExtractionIntoFolder()
        {
            using (var extractor = Extractor.FromStream(new MemoryStream(_archiveData), _sandbox, Model.Archive.MimeTypeZip))
                extractor.Run();

            Assert.IsTrue(Directory.Exists(_sandbox));
            var comparer = new CompareHierarchyToExtractedFolder(_sandbox);

            _package.AcceptVisitor(comparer);
        }
Exemple #3
0
        public void TestExtractInvalidData()
        {
            if (!WindowsUtils.IsWindows)
            {
                Assert.Ignore("CAB extraction relies on a Win32 API and therefore will not work on non-Windows platforms");
            }

            using (var sandbox = new TemporaryDirectory("0install-unit-tests"))
                Assert.Throws <IOException>(() => Extractor.FromStream(new MemoryStream(_garbageData), sandbox, Archive.MimeTypeCab));
        }
        public void EnsureSubDirDoesNotTouchFileNames()
        {
            using (var extractor = Extractor.FromStream(new MemoryStream(_archiveData), _sandbox, Model.Archive.MimeTypeZip))
            {
                extractor.SubDir = "/sub/folder/nested";
                extractor.Run();
            }

            Assert.IsFalse(Directory.Exists(Path.Combine(_sandbox, "Folder")), "Should not apply subdir matching to part of filename");
            Assert.IsFalse(File.Exists(Path.Combine(_sandbox, "File")), "Should not apply subdir matching to part of filename");
        }
        private void TestExtract(string mimeType, Stream archive)
        {
            using (var extractor = Extractor.FromStream(archive, _sandbox, mimeType))
                extractor.Run();

            Assert.IsTrue(File.Exists("subdir1/regular"), "Should extract file 'regular'");
            Assert.AreEqual(new DateTime(2000, 1, 1, 12, 0, 0), File.GetLastWriteTimeUtc("subdir1/regular"), "Correct last write time for file 'regular' should be set");

            Assert.IsTrue(File.Exists("subdir2/executable"), "Should extract file 'executable'");
            Assert.AreEqual(new DateTime(2000, 1, 1, 12, 0, 0), File.GetLastWriteTimeUtc("subdir2/executable"), "Correct last write time for file 'executable' should be set");
        }
        public void TestFileExtract()
        {
            using (var stream = typeof(ExtractorTest).GetEmbeddedStream("testArchive.zip"))
                using (var extractor = Extractor.FromStream(stream, _sandbox, Model.Archive.MimeTypeZip))
                    extractor.Run();

            Assert.IsTrue(File.Exists(Path.Combine(_sandbox, "subdir1/regular")), "Should extract file 'regular'");
            Assert.AreEqual(new DateTime(2000, 1, 1, 13, 0, 0), File.GetLastWriteTimeUtc(Path.Combine(_sandbox, "subdir1/regular")), "Correct last write time for file 'regular' should be set");

            Assert.IsTrue(File.Exists(Path.Combine(_sandbox, "subdir2/executable")), "Should extract file 'executable'");
            Assert.AreEqual(new DateTime(2000, 1, 1, 13, 0, 0), File.GetLastWriteTimeUtc(Path.Combine(_sandbox, "subdir2/executable")), "Correct last write time for file 'executable' should be set");
        }
        public void ExtractionOfSubDir()
        {
            using (var extractor = Extractor.FromStream(new MemoryStream(_archiveData), _sandbox, Model.Archive.MimeTypeZip))
            {
                extractor.SubDir = "/sub/folder/";
                extractor.Run();
            }

            Assert.IsTrue(Directory.Exists(Path.Combine(_sandbox, "nestedFolder")));
            Assert.AreEqual(PackageBuilder.DefaultDate, Directory.GetLastWriteTimeUtc(Path.Combine(_sandbox, "nestedFolder")));
            Assert.IsTrue(File.Exists(Path.Combine(_sandbox, "nestedFile")));
            Assert.IsFalse(File.Exists(Path.Combine(_sandbox, "file1")));
            Assert.IsFalse(File.Exists(Path.Combine(_sandbox, "file2")));
        }
        public void TestExtractOverwritingExistingItems()
        {
            File.WriteAllText(Path.Combine(_sandbox, "file1"), @"Wrong content");
            File.WriteAllText(Path.Combine(_sandbox, "file0"), @"This file should not be touched");

            using (var extractor = Extractor.FromStream(new MemoryStream(_archiveData), _sandbox, Model.Archive.MimeTypeZip))
                extractor.Run();

            Assert.IsTrue(File.Exists(Path.Combine(_sandbox, "file0")), "Extractor cleaned directory.");
            string file0Content = File.ReadAllText(Path.Combine(_sandbox, "file0"));

            Assert.AreEqual("This file should not be touched", file0Content);
            var comparer = new CompareHierarchyToExtractedFolder(_sandbox);

            _package.AcceptVisitor(comparer);
        }
Exemple #9
0
        public void TestExtractSubDir()
        {
            if (!WindowsUtils.IsWindows)
            {
                Assert.Ignore("CAB extraction relies on a Win32 API and therefore will not work on non-Windows platforms");
            }

            using (var stream = typeof(ExtractorTest).GetEmbeddedStream("testArchive.cab"))
                using (var sandbox = new TemporaryDirectory("0install-unit-tests"))
                    using (var extractor = Extractor.FromStream(stream, sandbox, Archive.MimeTypeCab))
                    {
                        extractor.SubDir = "folder1";
                        extractor.Run();

                        string filePath = Path.Combine(sandbox, "file");
                        Assert.IsTrue(File.Exists(filePath), "Should extract file 'dir/file'");
                        Assert.AreEqual(new DateTime(2000, 1, 1, 13, 0, 0), File.GetLastWriteTimeUtc(filePath), "Correct last write time should be set");
                        Assert.AreEqual("def", File.ReadAllText(filePath));
                    }
        }
Exemple #10
0
        public void TestCreateExtractor()
        {
            using (var tempDir = new TemporaryDirectory("0install-unit-tests"))
            {
                string path = Path.Combine(tempDir, "a.zip");

                using (var file = File.Create(path))
                    using (var zipStream = new ZipOutputStream(file)
                    {
                        IsStreamOwner = false
                    })
                    {
                        var entry = new ZipEntry("file");
                        zipStream.PutNextEntry(entry);
                        zipStream.CloseEntry();
                    }

                using (var extractor = Extractor.FromStream(File.OpenRead(path), tempDir, Model.Archive.MimeTypeZip))
                    Assert.IsInstanceOf(typeof(ZipExtractor), extractor);
            }
        }