Exemple #1
0
    public void MissingFiles()
    {
        TempDir.Dispose();

        using var operation = new ClearDirectory(TempDir, Manifest, new SilentTaskHandler());
        operation.Stage();
        operation.Commit();
    }
Exemple #2
0
    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.");
    }
Exemple #3
0
    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.");
    }
Exemple #4
0
    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.");
    }
Exemple #5
0
    /// <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 NETFRAMEWORK
        if (MachineWide)
        {
            ServiceStop();
            ServiceUninstall();
            NgenRemove();
        }
#endif

        try
        {
            if (WindowsUtils.IsWindows)
            {
                TargetMutexAcquire();
            }

            using (var clearDir = new ClearDirectory(TargetDir, targetManifest, Handler)
            {
                NoRestart = true
            })
            {
                clearDir.Stage();
#if NETFRAMEWORK
                DeleteServiceLogFiles();
#endif
                if (Portable)
                {
                    File.Delete(Path.Combine(TargetDir, Locations.PortableFlagName));
                }
                clearDir.Commit();
            }

            if (!Portable && WindowsUtils.IsWindows)
            {
                DesktopIntegrationRemove();
                ZeroInstallInstance.UnregisterLocation(MachineWide);
            }
        }
        finally
        {
            if (WindowsUtils.IsWindows)
            {
                TargetMutexRelease();
            }
        }
    }
Exemple #6
0
        /// <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();
            }
        }
Exemple #7
0
    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>
    /// <param name="libraryMode">Deploy Zero Install as a library for use by other applications without its own desktop integration.</param>
    /// <exception cref="UnauthorizedAccessException">Access to a resource was denied.</exception>
    /// <exception cref="IOException">An IO operation failed.</exception>
    public void Deploy(bool libraryMode = false)
    {
        if (Portable && libraryMode)
        {
            throw new ArgumentException(string.Format(Resources.CannotUseOptionsTogether, "--portable", "--library"), nameof(libraryMode));
        }

        var newManifest = LoadManifest(Locations.InstallBase);
        var oldManifest = LoadManifest(TargetDir);

        try
        {
            MutexAcquire();

            if (!FileUtils.PathEquals(TargetDir, Locations.InstallBase))
            {
                if (MachineWide)
                {
                    ServiceStop();
                }

                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)
            {
                if (!libraryMode)
                {
                    DesktopIntegrationApply(newManifest.TotalSize);
                }
                ZeroInstallInstance.RegisterLocation(TargetDir, MachineWide, libraryMode);
                RemoveOneGetBootstrap();
            }

            MutexRelease();

            if (MachineWide)
            {
                NgenApply();
                if (ServiceInstall())
                {
                    ServiceStart();
                }
                TaskSchedulerApply(libraryMode);
            }
        }
        catch
        {
            MutexRelease();
            throw;
        }
    }
Exemple #9
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;
            }
        }