Пример #1
0
        public async Task RunningUpgradeAppTwiceDoesntCrash()
        {
            string tempDir;
            string remotePkgDir;

            using (Utility.WithTempDirectory(out tempDir))
                using (Utility.WithTempDirectory(out remotePkgDir)) {
                    IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir);
                    var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
                    ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));

                    using (var fixture = new UpdateManager(remotePkgDir, "theApp", tempDir)) {
                        await fixture.FullInstall();
                    }

                    await Task.Delay(1000);

                    IntegrationTestHelper.CreateFakeInstalledApp("0.2.0", remotePkgDir);
                    pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
                    ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));

                    using (var fixture = new UpdateManager(remotePkgDir, "theApp", tempDir)) {
                        await fixture.UpdateApp();
                    }

                    await Task.Delay(1000);

                    // NB: The 2nd time we won't have any updates to apply. We should just do nothing!
                    using (var fixture = new UpdateManager(remotePkgDir, "theApp", tempDir)) {
                        await fixture.UpdateApp();
                    }

                    await Task.Delay(1000);
                }
        }
Пример #2
0
        public async Task CleanInstallRunsSquirrelAwareAppsWithInstallFlag()
        {
            string tempDir;
            string remotePkgDir;

            using (Utility.WithTempDirectory(out tempDir))
                using (Utility.WithTempDirectory(out remotePkgDir)) {
                    IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir);
                    var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
                    ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));

                    using (var fixture = new UpdateManager(remotePkgDir, "theApp", tempDir)) {
                        await fixture.FullInstall();

                        // NB: We execute the Squirrel-aware apps, so we need to give
                        // them a minute to settle or else the using statement will
                        // try to blow away a running process
                        await Task.Delay(1000);

                        Assert.False(File.Exists(Path.Combine(tempDir, "theApp", "app-0.1.0", "args2.txt")));
                        Assert.True(File.Exists(Path.Combine(tempDir, "theApp", "app-0.1.0", "args.txt")));

                        var text = File.ReadAllText(Path.Combine(tempDir, "theApp", "app-0.1.0", "args.txt"), Encoding.UTF8);
                        Assert.Contains("firstrun", text);
                    }
                }
        }
Пример #3
0
        public async Task UpgradeRunsSquirrelAwareAppsWithUpgradeFlag()
        {
            string tempDir;
            string remotePkgDir;

            using (Utility.WithTempDirectory(out tempDir))
                using (Utility.WithTempDirectory(out remotePkgDir)) {
                    IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir);
                    var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
                    ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));

                    using (var fixture = new UpdateManager(remotePkgDir, "theApp", tempDir)) {
                        await fixture.FullInstall();
                    }

                    await Task.Delay(1000);

                    IntegrationTestHelper.CreateFakeInstalledApp("0.2.0", remotePkgDir);
                    pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
                    ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));

                    using (var fixture = new UpdateManager(remotePkgDir, "theApp", tempDir)) {
                        await fixture.UpdateApp();
                    }

                    await Task.Delay(1000);

                    Assert.False(File.Exists(Path.Combine(tempDir, "theApp", "app-0.2.0", "args2.txt")));
                    Assert.True(File.Exists(Path.Combine(tempDir, "theApp", "app-0.2.0", "args.txt")));

                    var text = File.ReadAllText(Path.Combine(tempDir, "theApp", "app-0.2.0", "args.txt"), Encoding.UTF8);
                    Assert.Contains("updated|0.2.0", text);
                }
        }
Пример #4
0
        static int Main(string[] args)
        {
            var optParams = ParseCommands.ParseOptions(args);

            if (optParams == null)
            {
                return(-1);
            }

            var targetDir  = optParams["target"];
            var package    = new ReleasePackage(optParams["input"]);
            var targetFile = Path.Combine(targetDir, package.SuggestedReleaseFileName);

            string fullRelease;

            try {
                fullRelease = package.CreateReleasePackage(targetFile,
                                                           optParams["pkgdir"] != "" ? optParams["pkgdir"] : null,
                                                           input => (new Markdown()).Transform(input));
            }
            catch (Exception ex) {
                Console.Error.WriteLine();
                Console.Error.WriteLine("Unexpected exception occurred creating package:");
                Console.Error.WriteLine(ex);
                Console.Error.WriteLine();
                Console.Error.WriteLine();
                return(-4);
            }

            Console.WriteLine("{0};", fullRelease);

            var releaseFile = Path.Combine(targetDir, "RELEASES");

            if (File.Exists(releaseFile))
            {
                var releasesText   = File.ReadAllText(releaseFile, Encoding.UTF8);
                var releaseEntries = ReleaseEntry.ParseReleaseFile(releasesText);

                var previousFullRelease = ReleaseEntry.GetPreviousRelease(releaseEntries, package, targetDir);

                if (previousFullRelease != null &&
                    File.Exists(previousFullRelease.ReleasePackageFile))
                {
                    var deltaFile = Path.Combine(targetDir, package.SuggestedReleaseFileName.Replace("full", "delta"));
                    Console.WriteLine("{0}; {1}", previousFullRelease.InputPackageFile, deltaFile);

                    if (File.Exists(deltaFile))
                    {
                        File.Delete(deltaFile);
                    }

                    var deltaBuilder = new DeltaPackageBuilder();
                    deltaBuilder.CreateDeltaPackage(previousFullRelease, package, deltaFile);
                }
            }

            ReleaseEntry.BuildReleasesFile(targetDir);

            return(0);
        }
Пример #5
0
        public IObservable <Unit> UpdateLocalReleasesFile()
        {
            var noLock = checkForLock <Unit>();

            if (noLock != null)
            {
                return(noLock);
            }

            return(Observable.Start(() =>
                                    ReleaseEntry.BuildReleasesFile(PackageDirectory, fileSystem), RxApp.TaskpoolScheduler));
        }
Пример #6
0
            public void WhenTwoRemoteUpdatesAreAvailableChoosesDeltaVersion()
            {
                string tempDir;

                using (Utility.WithTempDirectory(out tempDir))
                {
                    var localPackages  = Path.Combine(tempDir, "theApp", "packages");
                    var remotePackages = Path.Combine(tempDir, "releases");
                    Directory.CreateDirectory(localPackages);
                    Directory.CreateDirectory(remotePackages);

                    new[] {
                        "Squirrel.Core.1.0.0.0-full.nupkg",
                    }.ForEach(x =>
                    {
                        var path = IntegrationTestHelper.GetPath("fixtures", x);
                        File.Copy(path, Path.Combine(localPackages, x));
                    });

                    new[] {
                        "Squirrel.Core.1.0.0.0-full.nupkg",
                        "Squirrel.Core.1.1.0.0-delta.nupkg",
                        "Squirrel.Core.1.1.0.0-full.nupkg",
                    }.ForEach(x =>
                    {
                        var path = IntegrationTestHelper.GetPath("fixtures", x);
                        File.Copy(path, Path.Combine(remotePackages, x));
                    });

                    var urlDownloader = new Mock <IUrlDownloader>();
                    var fixture       = new UpdateManager(remotePackages, "theApp", FrameworkVersion.Net40, tempDir, null, urlDownloader.Object);

                    UpdateInfo updateInfo;
                    using (fixture)
                    {
                        // sync both release files
                        fixture.UpdateLocalReleasesFile().Last();
                        ReleaseEntry.BuildReleasesFile(remotePackages);

                        updateInfo = fixture.CheckForUpdate().Wait();

                        Assert.True(updateInfo.ReleasesToApply.First().IsDelta);

                        updateInfo = fixture.CheckForUpdate(ignoreDeltaUpdates: true).Wait();

                        Assert.False(updateInfo.ReleasesToApply.First().IsDelta);
                    }
                }
            }
Пример #7
0
            public void WhenRemoteReleasesDoNotHaveDeltasNoUpdatesAreApplied()
            {
                string tempDir;

                using (Utility.WithTempDirectory(out tempDir))
                {
                    var localPackages  = Path.Combine(tempDir, "theApp", "packages");
                    var remotePackages = Path.Combine(tempDir, "releases");
                    Directory.CreateDirectory(localPackages);
                    Directory.CreateDirectory(remotePackages);

                    new[] {
                        "Squirrel.Core.1.0.0.0-full.nupkg",
                        "Squirrel.Core.1.1.0.0-delta.nupkg",
                        "Squirrel.Core.1.1.0.0-full.nupkg",
                    }.ForEach(x =>
                    {
                        var path = IntegrationTestHelper.GetPath("fixtures", x);
                        File.Copy(path, Path.Combine(localPackages, x));
                    });

                    new[] {
                        "Squirrel.Core.1.0.0.0-full.nupkg",
                        "Squirrel.Core.1.1.0.0-full.nupkg",
                    }.ForEach(x =>
                    {
                        var path = IntegrationTestHelper.GetPath("fixtures", x);
                        File.Copy(path, Path.Combine(remotePackages, x));
                    });

                    var urlDownloader = new Mock <IUrlDownloader>();
                    var fixture       = new UpdateManager(remotePackages, "theApp", FrameworkVersion.Net40, tempDir, null, urlDownloader.Object);

                    UpdateInfo updateInfo;
                    using (fixture)
                    {
                        // sync both release files
                        fixture.UpdateLocalReleasesFile().Last();
                        ReleaseEntry.BuildReleasesFile(remotePackages);

                        // check for an update
                        updateInfo = fixture.CheckForUpdate().Wait();
                    }

                    Assert.NotNull(updateInfo);
                    Assert.Empty(updateInfo.ReleasesToApply);
                }
            }
            public async Task WhenTwoRemoteUpdatesAreAvailableChoosesDeltaVersion()
            {
                string tempDir;

                using (Utility.WithTempDirectory(out tempDir))
                {
                    var appDir         = Path.Combine(tempDir, "theApp");
                    var localPackages  = Path.Combine(appDir, "packages");
                    var remotePackages = Path.Combine(tempDir, "releases");
                    Directory.CreateDirectory(localPackages);
                    Directory.CreateDirectory(remotePackages);

                    new[] { "Squirrel.Core.1.0.0.0-full.nupkg", }.ForEach(x => {
                        var path = IntegrationTestHelper.GetPath("fixtures", x);
                        File.Copy(path, Path.Combine(localPackages, x));
                    });

                    new[] {
                        "Squirrel.Core.1.0.0.0-full.nupkg",
                        "Squirrel.Core.1.1.0.0-delta.nupkg",
                        "Squirrel.Core.1.1.0.0-full.nupkg",
                    }.ForEach(x => {
                        var path = IntegrationTestHelper.GetPath("fixtures", x);
                        File.Copy(path, Path.Combine(remotePackages, x));
                    });

                    var fixture = new UpdateManager.ApplyReleasesImpl(appDir);

                    // sync both release files
                    await fixture.updateLocalReleasesFile();

                    ReleaseEntry.BuildReleasesFile(remotePackages);

                    using (var mgr = new UpdateManager(remotePackages, "theApp", tempDir, new FakeUrlDownloader())) {
                        UpdateInfo updateInfo;
                        updateInfo = await mgr.CheckForUpdate();

                        Assert.True(updateInfo.ReleasesToApply.First().IsDelta);

                        updateInfo = await mgr.CheckForUpdate(ignoreDeltaUpdates : true);

                        Assert.False(updateInfo.ReleasesToApply.First().IsDelta);
                    }
                }
            }
            public async Task WhenRemoteReleasesDoNotHaveDeltasNoUpdatesAreApplied()
            {
                string tempDir;

                using (Utility.WithTempDirectory(out tempDir))
                {
                    var appDir         = Path.Combine(tempDir, "theApp");
                    var localPackages  = Path.Combine(appDir, "packages");
                    var remotePackages = Path.Combine(tempDir, "releases");
                    Directory.CreateDirectory(localPackages);
                    Directory.CreateDirectory(remotePackages);

                    new[] {
                        "Squirrel.Core.1.0.0.0-full.nupkg",
                        "Squirrel.Core.1.1.0.0-delta.nupkg",
                        "Squirrel.Core.1.1.0.0-full.nupkg",
                    }.ForEach(x => {
                        var path = IntegrationTestHelper.GetPath("fixtures", x);
                        File.Copy(path, Path.Combine(localPackages, x));
                    });

                    new[] {
                        "Squirrel.Core.1.0.0.0-full.nupkg",
                        "Squirrel.Core.1.1.0.0-full.nupkg",
                    }.ForEach(x => {
                        var path = IntegrationTestHelper.GetPath("fixtures", x);
                        File.Copy(path, Path.Combine(remotePackages, x));
                    });

                    var fixture = new UpdateManager.ApplyReleasesImpl(appDir);

                    // sync both release files
                    await fixture.updateLocalReleasesFile();

                    ReleaseEntry.BuildReleasesFile(remotePackages);

                    UpdateInfo updateInfo;
                    using (var mgr = new UpdateManager(remotePackages, "theApp", tempDir, new FakeUrlDownloader())) {
                        updateInfo = await mgr.CheckForUpdate();
                    }

                    Assert.NotNull(updateInfo);
                    Assert.Empty(updateInfo.ReleasesToApply);
                }
            }
Пример #10
0
        static int Main(string[] args)
        {
            var optParams = parseOptions(args);

            if (optParams == null)
            {
                return(-1);
            }

            var targetDir  = optParams["target"];
            var package    = new ReleasePackage(optParams["input"]);
            var targetFile = Path.Combine(targetDir, package.SuggestedReleaseFileName);

            var fullRelease = package.CreateReleasePackage(targetFile,
                                                           optParams["pkgdir"] != "" ? optParams["pkgdir"] : null,
                                                           input => (new Markdown()).Transform(input));

            var releaseFile = Path.Combine(targetDir, "RELEASES");

            if (File.Exists(releaseFile))
            {
                var releaseEntries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releaseFile, Encoding.UTF8));

                var latestFullRelease = releaseEntries
                                        .Where(x => x.IsDelta == false)
                                        .MaxBy(x => x.Version)
                                        .Select(x => new ReleasePackage(Path.Combine(targetDir, x.Filename), true))
                                        .FirstOrDefault();

                var deltaFile = Path.Combine(targetDir, package.SuggestedReleaseFileName.Replace("full", "delta"));
                Console.WriteLine("{0} {1}", latestFullRelease.InputPackageFile, deltaFile);

                var deltaBuilder = new DeltaPackageBuilder();
                deltaBuilder.CreateDeltaPackage(package, latestFullRelease, deltaFile);
            }

            ReleaseEntry.BuildReleasesFile(targetDir);

            Console.WriteLine(fullRelease);
            return(0);
        }
Пример #11
0
        public async Task FullUninstallRemovesAllVersions()
        {
            string tempDir;
            string remotePkgDir;

            using (Utility.WithTempDirectory(out tempDir))
                using (Utility.WithTempDirectory(out remotePkgDir)) {
                    IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir);
                    var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
                    ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));

                    using (var fixture = new UpdateManager(remotePkgDir, "theApp", tempDir)) {
                        await fixture.FullInstall();
                    }

                    await Task.Delay(1000);

                    IntegrationTestHelper.CreateFakeInstalledApp("0.2.0", remotePkgDir);
                    pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
                    ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));

                    using (var fixture = new UpdateManager(remotePkgDir, "theApp", tempDir)) {
                        await fixture.UpdateApp();
                    }

                    await Task.Delay(1000);

                    using (var fixture = new UpdateManager(remotePkgDir, "theApp", tempDir)) {
                        await fixture.FullUninstall();
                    }

                    Assert.False(File.Exists(Path.Combine(tempDir, "theApp", "app-0.1.0", "args.txt")));
                    Assert.False(File.Exists(Path.Combine(tempDir, "theApp", "app-0.2.0", "args.txt")));
                    Assert.True(File.Exists(Path.Combine(tempDir, "theApp", "app-0.2.0", ".dead")));
                }
        }
Пример #12
0
 public IObservable <Unit> UpdateLocalReleasesFile()
 {
     return(acquireUpdateLock().SelectMany(_ => Observable.Start(() =>
                                                                 ReleaseEntry.BuildReleasesFile(PackageDirectory, fileSystem), RxApp.TaskpoolScheduler)));
 }
Пример #13
0
        public void ApplyMultipleDeltaPackagesGeneratesCorrectHash()
        {
            var firstRelease  = new ReleasePackage(IntegrationTestHelper.GetPath("fixtures", "SquirrelDesktopDemo-1.0.0-full.nupkg"), true);
            var secondRelease = new ReleasePackage(IntegrationTestHelper.GetPath("fixtures", "SquirrelDesktopDemo-1.1.0-full.nupkg"), true);
            var thirdRelease  = new ReleasePackage(IntegrationTestHelper.GetPath("fixtures", "SquirrelDesktopDemo-1.2.0-full.nupkg"), true);

            string installDir, releasesDir;

            using (Utility.WithTempDirectory(out releasesDir))
                using (IntegrationTestHelper.WithFakeAlreadyInstalledApp("InstalledSquirrelDesktopDemo-1.0.0.zip", out installDir)) {
                    var firstDelta  = Path.Combine(releasesDir, "SquirrelDesktopDemo-1.1.0-delta.nupkg");
                    var secondDelta = Path.Combine(releasesDir, "SquirrelDesktopDemo-1.2.0-delta.nupkg");


                    new[] { firstRelease, secondRelease, thirdRelease }
                    .ForEach(file =>
                    {
                        var packageFile = file.ReleasePackageFile;
                        var fileName    = Path.GetFileName(packageFile);
                        File.Copy(packageFile, Path.Combine(releasesDir, fileName));
                    });

                    var deltaBuilder = new DeltaPackageBuilder();
                    deltaBuilder.CreateDeltaPackage(firstRelease, secondRelease, firstDelta);
                    deltaBuilder.CreateDeltaPackage(secondRelease, thirdRelease, secondDelta);

                    ReleaseEntry.BuildReleasesFile(releasesDir);

                    var updateManager = new UpdateManager(
                        releasesDir, "ShimmerDesktopDemo", FrameworkVersion.Net40, installDir);

                    using (updateManager) {
                        var updateInfo = updateManager.CheckForUpdate().First();

                        Assert.Equal(2, updateInfo.ReleasesToApply.Count());

                        updateManager.DownloadReleases(updateInfo.ReleasesToApply).Wait();
                        updateManager.ApplyReleases(updateInfo).Wait();
                    }

                    string referenceDir;
                    using (IntegrationTestHelper.WithFakeAlreadyInstalledApp("InstalledSquirrelDesktopDemo-1.2.0.zip", out referenceDir)) {
                        var referenceVersion = Path.Combine(referenceDir, "ShimmerDesktopDemo", "app-1.2.0");
                        var installVersion   = Path.Combine(installDir, "ShimmerDesktopDemo", "app-1.2.0");

                        var referenceFiles = Directory.GetFiles(referenceVersion);
                        var actualFiles    = Directory.GetFiles(installVersion);

                        Assert.Equal(referenceFiles.Count(), actualFiles.Count());

                        var invalidFiles =
                            Enumerable.Zip(referenceFiles, actualFiles,
                                           (reference, actual) => {
                            var refSha    = Utility.CalculateFileSHA1(reference);
                            var actualSha = Utility.CalculateFileSHA1(actual);

                            return(new { File = actual, Result = refSha == actualSha });
                        })
                            .Where(c => !c.Result).ToArray();

                        Assert.Empty(invalidFiles);
                    }
                }
        }
 internal async Task <List <ReleaseEntry> > UpdateLocalReleasesFile()
 {
     return(await Task.Run(() => ReleaseEntry.BuildReleasesFile(Utility.PackageDirectoryForAppDir(rootAppDirectory))));
 }