public void MissingFiles() { TempDir.Dispose(); using var operation = new ClearDirectory(TempDir, Manifest, new SilentTaskHandler()); operation.Stage(); operation.Commit(); }
public void StageAndRollBack() { using (var operation = new ClearDirectory(TempDir, Manifest, new SilentTaskHandler())) { operation.Stage(); // Missing .Commit() automatically triggers rollback } File.Exists(File1Path).Should().BeTrue(because: "Original file should be back after rollback."); File.Exists(File2Path).Should().BeTrue(because: "Original file should be back after rollback."); }
public void UntrackedFilesInTarget() { FileUtils.Touch(Path.Combine(TempDir, "untracked")); using (var operation = new ClearDirectory(TempDir, Manifest, new SilentTaskHandler())) { operation.Stage(); operation.Commit(); } Directory.GetFileSystemEntries(TempDir).Length.Should().Be(1, because: "Only untracked file should be left after commit."); }
public void ReadOnlyAttribute() { Skip.IfNot(WindowsUtils.IsWindows, "Read-only file attribute is only available on Windows"); new FileInfo(File1Path).IsReadOnly = true; using (var operation = new ClearDirectory(TempDir, Manifest, new SilentTaskHandler())) { operation.Stage(); operation.Commit(); } Directory.Exists(TempDir).Should().BeFalse(because: "Entire directory should be gone after commit."); }
public void ReadOnlyAttribute() { if (!WindowsUtils.IsWindows) Assert.Ignore("Read-only file attribute is only available on Windows"); new FileInfo(File1Path).IsReadOnly = true; using (var operation = new ClearDirectory(TempDir, Manifest, new SilentTaskHandler())) { operation.Stage(); operation.Commit(); } Directory.Exists(TempDir).Should().BeFalse(because: "Entire directory should be gone after commit."); }
public void StageAndCommit() { string manifestPath = Path.Combine(TempDir, Manifest.ManifestFile); FileUtils.Touch(manifestPath); // Content of Manifest file is not read, in-memory Manifest is used instead using (var operation = new ClearDirectory(TempDir, Manifest, new SilentTaskHandler())) { operation.Stage(); File.Exists(manifestPath).Should().BeFalse(because: "Original manifest file should be gone after staging."); File.Exists(File1Path).Should().BeFalse(because: "Original file should be gone after staging."); Directory.Exists(SubdirPath).Should().BeTrue(because: "Directories should be left intact after staging."); File.Exists(File2Path).Should().BeFalse(because: "Original file should be gone after staging."); Directory.GetFileSystemEntries(TempDir).Length.Should().Be(3, because: "Backup files should be preset after staging."); Directory.GetFileSystemEntries(SubdirPath).Length.Should().Be(1, because: "Backup files should be preset after staging."); operation.Commit(); } Directory.Exists(TempDir).Should().BeFalse(because: "Entire directory should be gone after commit."); }
/// <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; } }
/// <summary> /// Runs the removal process. /// </summary> /// <exception cref="UnauthorizedAccessException">Access to a resource was denied.</exception> /// <exception cref="IOException">An IO operation failed.</exception> public void Remove() { var targetManifest = LoadManifest(TargetDir); if (targetManifest == null) throw new IOException(Resources.MaintenanceMissingManifest); if (WindowsUtils.IsWindows && MachineWide) { ServiceStop(); ServiceUninstall(); NgenRemove(); } try { TargetMutexAquire(); using (var clearDir = new ClearDirectory(TargetDir, targetManifest, Handler) {NoRestart = true}) { clearDir.Stage(); DeleteServiceLogFiles(); if (Portable) File.Delete(Path.Combine(TargetDir, Locations.PortableFlagName)); clearDir.Commit(); } if (!Portable) { if (WindowsUtils.IsWindows) RegistryRemove(); DesktopIntegrationRemove(); } } finally { TargetMutexRelease(); } }
public void MissingFiles() { TempDir.Dispose(); using (var operation = new ClearDirectory(TempDir, Manifest, new SilentTaskHandler())) { operation.Stage(); operation.Commit(); } }