Пример #1
0
        public void TestDirInUse()
        {
            var name0 = "TestDirInUse";
            var name1 = "TestDirInUse1";

            var result0 = TestOutputDirGen(RelativeDirectoryPath.Parse(name0));
            var result1 = TestOutputDirGen(RelativeDirectoryPath.Parse(name0));

            // Expects the base path to
            Assert.True(result0.OutputDir.Name == new DirectoryName(name0));
            Assert.True(result1.OutputDir.Name == new DirectoryName(name1));
        }
Пример #2
0
        public void TestDirReuse()
        {
            var name0 = "TestDirReuse";

            var result0 = TestOutputDirGen(RelativeDirectoryPath.Parse(name0));

            result0.LockFile.Dispose();
            var result1 = TestOutputDirGen(RelativeDirectoryPath.Parse(name0));

            // Expects the base path to
            Assert.True(result0.OutputDir.Name == new DirectoryName(name0));
            Assert.True(result1.OutputDir.Name == new DirectoryName(name0));
        }
Пример #3
0
        static void ExtractZipTo(CancellationToken ct, Stream stream, AbsoluteDirectoryPath outFolder, IProgress <InstallerEvent> progress)
        {
            progress.Report(new InstallerStep("Extracting"));

            var zipIn    = new ZipInputStream(stream);
            var zipEntry = zipIn.GetNextEntry();

            if (zipEntry.IsDirectory)
            {
                zipEntry = zipIn.GetNextEntry();
            }

            while (zipEntry != null)
            {
                ct.ThrowIfCancellationRequested();
                var entryFileName = zipEntry.Name;
                var parts         = zipEntry.IsDirectory ? RelativeDirectoryPath.Parse(entryFileName.Substring(0, entryFileName.Length - 1)).Parts :
                                    RelativeFilePath.Parse(entryFileName).Parts;

                var newPathStr = "";
                var partsArray = parts.ToArray();
                for (var i = 1; i < partsArray.Length; ++i)
                {
                    newPathStr += partsArray[i] + (i + 1 == partsArray.Length ? "" : Path.DirectorySeparatorChar.ToString());
                }

                var buffer        = new byte[4096];
                var fullZipToPath = Path.Combine(outFolder.NativePath, newPathStr);
                var directoryName = zipEntry.IsFile ? Path.GetDirectoryName(fullZipToPath) : fullZipToPath;
                if (directoryName.Length > 0)
                {
                    Directory.CreateDirectory(directoryName);
                }

                if (zipEntry.IsFile)
                {
                    progress.Report(new InstallerMessage("Extracting: " + newPathStr));
                    using (var streamWriter = File.Create(fullZipToPath))
                    {
                        StreamUtils.Copy(zipIn, streamWriter, buffer);
                    }
                }

                zipEntry = zipIn.GetNextEntry();
            }
        }
Пример #4
0
        public void TestDirInUseSimultaneously()
        {
            var name = "TestDirInUseSim";

            var listOfPossibilities = new List <DirectoryName>
            {
                new DirectoryName("TestDirInUseSim"),
                new DirectoryName("TestDirInUseSim1"),
                new DirectoryName("TestDirInUseSim2"),
                new DirectoryName("TestDirInUseSim3"),
                new DirectoryName("TestDirInUseSim4")
            };

            var result0 = Task.Run(() => TestOutputDirGen(RelativeDirectoryPath.Parse(name)));
            var result1 = Task.Run(() => TestOutputDirGen(RelativeDirectoryPath.Parse(name)));
            var result2 = Task.Run(() => TestOutputDirGen(RelativeDirectoryPath.Parse(name)));
            var result3 = Task.Run(() => TestOutputDirGen(RelativeDirectoryPath.Parse(name)));
            var result4 = Task.Run(() => TestOutputDirGen(RelativeDirectoryPath.Parse(name)));

            // Expects the base path to
            Assert.True(listOfPossibilities.Remove(result0.Result.OutputDir.Name));
            Assert.True(listOfPossibilities.Remove(result1.Result.OutputDir.Name));
            Assert.True(listOfPossibilities.Remove(result2.Result.OutputDir.Name));
            Assert.True(listOfPossibilities.Remove(result3.Result.OutputDir.Name));
            Assert.True(listOfPossibilities.Remove(result4.Result.OutputDir.Name));

            foreach (var r in new[] { result0, result1, result2, result3, result4 })
            {
                try
                {
                    r.Result.LockFile.Dispose();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Got error while trying to dispose lock in {0}: {1}", r.Result.OutputDir, e);
                    throw;
                }
            }
        }