Ejemplo n.º 1
0
        public void CanUseZipFileAsHierarchyRoot()
        {
            using (var temporaryDirectory = new TemporaryDirectory())
            {
                using (var zip = new ZipArchive(File.OpenWrite(temporaryDirectory.GetPath("test.zip")), ZipArchiveMode.Create))
                {
                    var nested = zip.CreateEntry("inside/archive.zip");
                    using (var nestedZip = new ZipArchive(nested.Open(), ZipArchiveMode.Create))
                    {
                        nestedZip.CreateEntry("directory/nestedFile.txt");
                    }
                }

                using (var buffer = new TemporaryDirectory())
                {
                    var hierarchy = new ZipFileSystemHierarchy(new FileInfo(temporaryDirectory.GetPath("test.zip")), buffer, suppressZipExtensions: false, caseSensitive: false);
                    var matcher   = new GlobMatchEnumerator(new GlobParser().Parse("**/*.txt"));

                    var results = matcher.EnumerateMatches(hierarchy).ToArray();

                    Assume.That(results, Has.Length.EqualTo(1));
                    Assert.That(results.Single().Details.GetPathSegments(), Is.EqualTo(new [] { "inside", "archive.zip", "directory", "nestedFile.txt" }));
                }
            }
        }
Ejemplo n.º 2
0
        public void SuppressedZipExtensionsAreNotMatched()
        {
            using (var temporaryDirectory = new TemporaryDirectory())
            {
                using (var zip = new ZipArchive(File.OpenWrite(temporaryDirectory.GetPath("test.zip")), ZipArchiveMode.Create))
                {
                    var nested = zip.CreateEntry("archive.zip");
                    using (var nestedZip = new ZipArchive(nested.Open(), ZipArchiveMode.Create))
                    {
                        nestedZip.CreateEntry("nestedA");
                        nestedZip.CreateEntry("nestedB");
                    }
                    zip.CreateEntry("outerA");
                    zip.CreateEntry("outerB");
                }

                using (var buffer = new TemporaryDirectory())
                {
                    var hierarchy = new ZipFileSystemHierarchy(new DirectoryInfo(temporaryDirectory.FullPath), buffer, suppressZipExtensions: true, caseSensitive: false);
                    var matcher   = new GlobMatchEnumerator(new GlobParser().Parse("test*/*.zip/*A"));

                    var results = matcher.EnumerateMatches(hierarchy).ToArray();

                    Assert.That(results, Is.Empty);
                }
            }
        }
Ejemplo n.º 3
0
        public void CanEnumerateFilesRecursivelyWithinZipArchives()
        {
            using (var temporaryDirectory = new TemporaryDirectory())
            {
                using (var zip = new ZipArchive(File.OpenWrite(temporaryDirectory.GetPath("test.zip")), ZipArchiveMode.Create))
                {
                    var nested = zip.CreateEntry("archive.zip");
                    using (var nestedZip = new ZipArchive(nested.Open(), ZipArchiveMode.Create))
                    {
                        nestedZip.CreateEntry("nestedA");
                        nestedZip.CreateEntry("nestedB");
                    }
                    zip.CreateEntry("outerA");
                    zip.CreateEntry("outerB");
                }

                using (var buffer = new TemporaryDirectory())
                {
                    var hierarchy = new ZipFileSystemHierarchy(new DirectoryInfo(temporaryDirectory.FullPath), buffer, suppressZipExtensions: false, caseSensitive: false);
                    var matcher   = new GlobMatchEnumerator(new GlobParser().Parse("test*/**/*A"));

                    var results = matcher.EnumerateMatches(hierarchy).ToArray();

                    Assert.That(results, Has.Length.EqualTo(2));
                    Assert.That(results.Select(r => r.Item.Exists), Has.All.True);
                }
            }
        }
Ejemplo n.º 4
0
        public void CreatesNewExtractedCopyForDifferentZipFile()
        {
            using (var temporaryDirectory = new TemporaryDirectory())
            {
                Directory.CreateDirectory(temporaryDirectory.GetPath("A"));
                using (var zipA = new ZipArchive(File.OpenWrite(temporaryDirectory.GetPath("A", "test.zip")), ZipArchiveMode.Create))
                {
                    zipA.CreateEntry("fileA");
                    zipA.CreateEntry("fileB");
                    zipA.CreateEntry("fileC");
                }
                Directory.CreateDirectory(temporaryDirectory.GetPath("B"));
                using (var zipB = new ZipArchive(File.OpenWrite(temporaryDirectory.GetPath("B", "test.zip")), ZipArchiveMode.Create))
                {
                    zipB.CreateEntry("fileA");
                    zipB.CreateEntry("fileB");
                    zipB.CreateEntry("fileC");
                }

                var zipFileA = new FileInfo(temporaryDirectory.GetPath("A", "test.zip"));
                var zipFileB = new FileInfo(temporaryDirectory.GetPath("B", "test.zip"));

                using (var buffer = new TemporaryDirectory())
                {
                    var cache = new ZipFileCache(buffer, caseSensitive: false);

                    var extractedA = cache.ExtractToCache(zipFileA);
                    var extractedB = cache.ExtractToCache(zipFileB);

                    Assert.That(extractedA, Is.Not.EqualTo(extractedB));
                }
            }
        }
Ejemplo n.º 5
0
        public void ReusesExtractedCopy()
        {
            using (var temporaryDirectory = new TemporaryDirectory())
            {
                using (var zip = new ZipArchive(File.OpenWrite(temporaryDirectory.GetPath("test.zip")), ZipArchiveMode.Create))
                {
                    zip.CreateEntry("fileA");
                    zip.CreateEntry("fileB");
                    zip.CreateEntry("fileC");
                }

                var zipFile = new FileInfo(temporaryDirectory.GetPath("test.zip"));

                using (var buffer = new TemporaryDirectory())
                {
                    var cache = new ZipFileCache(buffer, caseSensitive: false);

                    var extracted1 = cache.ExtractToCache(zipFile);
                    var extracted2 = cache.ExtractToCache(zipFile);

                    Assert.That(extracted1, Is.EqualTo(extracted2));
                }
            }
        }