Deploys/copies files listed in a Manifest file to another directory.
Inheritance: DirectoryOperation
Exemplo n.º 1
0
        public void StageAndRollBack()
        {
            Directory.Delete(_destinationDirectory);

            using (var operation = new DeployDirectory(TempDir, Manifest, _destinationDirectory, new SilentTaskHandler()))
            {
                operation.Stage();
                // Missing .Commit() automatically triggers rollback
            }

            Directory.Exists(_destinationDirectory).Should().BeFalse(because: "Directory should be gone after rollback.");
        }
Exemplo n.º 2
0
        public void PreExistingFiles()
        {
            FileUtils.Touch(Path.Combine(_destinationDirectory, "preexisting"));

            using (var operation = new DeployDirectory(TempDir, Manifest, _destinationDirectory, new SilentTaskHandler()))
            {
                operation.Stage();
                // Missing .Commit() automatically triggers rollback
            }

            Directory.GetFileSystemEntries(_destinationDirectory).Length.Should().Be(1, because: "All new content should be gone after rollback.");
        }
Exemplo n.º 3
0
        public void ReadOnlyAttribute()
        {
            Skip.IfNot(WindowsUtils.IsWindows, "Read-only file attribute is only available on Windows");

            FileUtils.Touch(_destinationFile1Path);
            new FileInfo(_destinationFile1Path).IsReadOnly = true;

            using (var operation = new DeployDirectory(TempDir, Manifest, _destinationDirectory, new SilentTaskHandler()))
            {
                operation.Stage();
                operation.Commit();
            }

            File.Exists(_destinationFile1Path).Should().BeTrue(because: "Final destination file should exist after commit.");
            File.Exists(_destinationFile2Path).Should().BeTrue(because: "Final destination file should exist after commit.");
        }
Exemplo n.º 4
0
        public void StageAndCommit()
        {
            Directory.Delete(_destinationDirectory);

            using (var operation = new DeployDirectory(TempDir, Manifest, _destinationDirectory, new SilentTaskHandler()))
            {
                operation.Stage();
                File.Exists(_destinationManifestPath).Should().BeFalse(because: "Final destination manifest file should not exist yet after staging.");
                File.Exists(_destinationFile1Path).Should().BeFalse(because: "Final destination file should not exist yet after staging.");
                Directory.Exists(_destinationSubdirPath).Should().BeTrue(because: "Directories should be created after staging.");
                File.Exists(_destinationFile2Path).Should().BeFalse(because: "Final destination file should not exist yet after staging.");
                Directory.GetFileSystemEntries(_destinationDirectory).Length.Should().Be(3, because: "Temp files should be preset after staging.");
                Directory.GetFileSystemEntries(_destinationSubdirPath).Length.Should().Be(1, because: "Temp files should be preset after staging.");

                operation.Commit();
            }

            Manifest.Load(_destinationManifestPath, Manifest.Format).Should().Equal(Manifest, because: "Destination manifest file should equal in-memory manifest used as copy instruction.");
            File.Exists(_destinationManifestPath).Should().BeTrue(because: "Final destination manifest file should exist after commit.");
            File.Exists(_destinationFile1Path).Should().BeTrue(because: "Final destination file should exist after commit.");
            File.Exists(_destinationFile2Path).Should().BeTrue(because: "Final destination file should exist after commit.");
        }
Exemplo n.º 5
0
        public void StageAndCommit()
        {
            Directory.Delete(_destinationDirectory);

            using (var operation = new DeployDirectory(TempDir, Manifest, _destinationDirectory, new SilentTaskHandler()))
            {
                operation.Stage();
                File.Exists(_destinationManifestPath).Should().BeFalse(because: "Final destination manifest file should not exist yet after staging.");
                File.Exists(_destinationFile1Path).Should().BeFalse(because: "Final destination file should not exist yet after staging.");
                Directory.Exists(_destinationSubdirPath).Should().BeTrue(because: "Directories should be created after staging.");
                File.Exists(_destinationFile2Path).Should().BeFalse(because: "Final destination file should not exist yet after staging.");
                Directory.GetFileSystemEntries(_destinationDirectory).Length.Should().Be(3, because: "Temp files should be preset after staging.");
                Directory.GetFileSystemEntries(_destinationSubdirPath).Length.Should().Be(1, because: "Temp files should be preset after staging.");

                operation.Commit();
            }

            Manifest.Load(_destinationManifestPath, Manifest.Format).Should().Equal(Manifest, because: "Destination manifest file should equal in-memory manifest used as copy instruction.");
            File.Exists(_destinationManifestPath).Should().BeTrue(because: "Final destination manifest file should exist after commit.");
            File.Exists(_destinationFile1Path).Should().BeTrue(because: "Final destination file should exist after commit.");
            File.Exists(_destinationFile2Path).Should().BeTrue(because: "Final destination file should exist after commit.");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Runs the deployment process.
        /// </summary>
        /// <exception cref="UnauthorizedAccessException">Access to a resource was denied.</exception>
        /// <exception cref="IOException">An IO operation failed.</exception>
        public void Deploy()
        {
            if (TargetDir == Locations.InstallBase)
                throw new InvalidOperationException(string.Format(Resources.SourceAndTargetSame, TargetDir));

            var newManifest = LoadManifest(Locations.InstallBase);
            if (newManifest == null) throw new IOException(Resources.MaintenanceMissingManifest);
            var oldManifest = LoadManifest(TargetDir) ?? LegacyManifest;

            if (WindowsUtils.IsWindows && MachineWide)
                ServiceStop();

            try
            {
                TargetMutexAquire();

                using (var clearDir = new ClearDirectory(TargetDir, oldManifest, Handler))
                using (var deployDir = new DeployDirectory(Locations.InstallBase, newManifest, TargetDir, Handler))
                {
                    deployDir.Stage();
                    clearDir.Stage();
                    if (Portable) FileUtils.Touch(Path.Combine(TargetDir, Locations.PortableFlagName));
                    deployDir.Commit();
                    clearDir.Commit();
                }

                if (!Portable)
                {
                    DesktopIntegrationApply();

                    if (WindowsUtils.IsWindows)
                    {
                        RegistryApply();
                        WindowsUtils.BroadcastMessage(PerformedWindowMessageID);
                        RemoveOneGetBootstrap();
                    }
                }

                TargetMutexRelease();

                if (WindowsUtils.IsWindows && MachineWide)
                {
                    NgenApply();
                    ServiceInstall();
                    ServiceStart();
                }
            }
            catch
            {
                TargetMutexRelease();
                throw;
            }
        }
Exemplo n.º 7
0
        public void PreExistingFiles()
        {
            FileUtils.Touch(Path.Combine(_destinationDirectory, "preexisting"));

            using (var operation = new DeployDirectory(TempDir, Manifest, _destinationDirectory, new SilentTaskHandler()))
            {
                operation.Stage();
                // Missing .Commit() automatically triggers rollback
            }

            Directory.GetFileSystemEntries(_destinationDirectory).Length.Should().Be(1, because: "All new content should be gone after rollback.");
        }
Exemplo n.º 8
0
        public void StageAndRollBack()
        {
            Directory.Delete(_destinationDirectory);

            using (var operation = new DeployDirectory(TempDir, Manifest, _destinationDirectory, new SilentTaskHandler()))
            {
                operation.Stage();
                // Missing .Commit() automatically triggers rollback
            }

            Directory.Exists(_destinationDirectory).Should().BeFalse(because: "Directory should be gone after rollback.");
        }
Exemplo n.º 9
0
        public void ReadOnlyAttribute()
        {
            if (!WindowsUtils.IsWindows) Assert.Ignore("Read-only file attribute is only available on Windows");

            FileUtils.Touch(_destinationFile1Path);
            new FileInfo(_destinationFile1Path).IsReadOnly = true;

            using (var operation = new DeployDirectory(TempDir, Manifest, _destinationDirectory, new SilentTaskHandler()))
            {
                operation.Stage();
                operation.Commit();
            }

            File.Exists(_destinationFile1Path).Should().BeTrue(because: "Final destination file should exist after commit.");
            File.Exists(_destinationFile2Path).Should().BeTrue(because: "Final destination file should exist after commit.");
        }