public static async Task CreateCatalogAsync(string root, string feedRoot, string nupkgFolder, Uri baseUri, int catalogPageSize, ILogger log)
        {
            using (var cache = new LocalCache())
            {
                var sleetConfig  = CreateSleetConfig(root, feedRoot, baseUri);
                var settings     = LocalSettings.Load(sleetConfig);
                var fileSystem   = FileSystemFactory.CreateFileSystem(settings, cache, "feed");
                var feedSettings = await FeedSettingsUtility.GetSettingsOrDefault(fileSystem, log, CancellationToken.None);

                feedSettings.CatalogEnabled  = true;
                feedSettings.SymbolsEnabled  = false;
                feedSettings.CatalogPageSize = catalogPageSize;

                var success = await InitCommand.InitAsync(settings, fileSystem, feedSettings, log, CancellationToken.None);

                if (success != true)
                {
                    throw new InvalidOperationException("Catalog init failed");
                }

                if (Directory.GetFiles(nupkgFolder).Any())
                {
                    success = await PushCommand.PushPackages(settings, fileSystem, new List <string>() { nupkgFolder }, false, false, log, CancellationToken.None);

                    if (success != true)
                    {
                        throw new InvalidOperationException("Push failed");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <ISet <PackageIdentity> > GetPackageIdentitiesAsync()
        {
            var context = new SleetContext
            {
                LocalSettings = GetSettings(),
                Log           = new SleetLogger(Log),
                Source        = GetAzureFileSystem(),
                Token         = CancellationToken
            };

            context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault(
                context.Source,
                context.Log,
                context.Token);

            var packageIndex = new PackageIndex(context);

            return(await packageIndex.GetPackagesAsync());
        }
Ejemplo n.º 3
0
        public async Task <ISet <PackageIdentity> > GetPackageIdentitiesAsync()
        {
            using (var fileCache = CreateFileCache())
            {
                var context = new SleetContext
                {
                    LocalSettings = GetSettings(),
                    Log           = new SleetLogger(Log, NuGet.Common.LogLevel.Verbose),
                    Source        = GetAzureFileSystem(fileCache),
                    Token         = CancellationToken
                };
                context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault(
                    context.Source,
                    context.Log,
                    context.Token);

                var packageIndex = new PackageIndex(context);

                return(await packageIndex.GetPackagesAsync());
            }
        }
        public async Task RetentionSettingsCommand_DisableRetention()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true,
                                SymbolsEnabled = true
                            }
                        };

                        await InitCommand.InitAsync(context);

                        // Enable retention
                        var success = await RetentionSettingsCommand.RunAsync(context.LocalSettings, context.Source, 10, 5, 2, false, log);

                        // Disable retention
                        success &= await RetentionSettingsCommand.RunAsync(context.LocalSettings, context.Source, -1, -1, true, log);

                        var updatedSettings = await FeedSettingsUtility.GetSettingsOrDefault(context.Source, log, context.Token);

                        success.Should().BeTrue();
                        updatedSettings.RetentionMaxStableVersions.Should().BeNull();
                        updatedSettings.RetentionMaxPrereleaseVersions.Should().BeNull();
                        updatedSettings.RetentionGroupByFirstPrereleaseLabelCount.Should().BeNull();
                    }
        }
Ejemplo n.º 5
0
        private async Task <bool> PushAsync(
            IEnumerable <string> items,
            PushOptions options)
        {
            LocalSettings   settings   = GetSettings();
            AzureFileSystem fileSystem = GetAzureFileSystem();
            SleetLogger     log        = new SleetLogger(Log);

            var packagesToPush = items.ToList();

            if (!options.AllowOverwrite && options.PassIfExistingItemIdentical)
            {
                var context = new SleetContext
                {
                    LocalSettings = settings,
                    Log           = log,
                    Source        = fileSystem,
                    Token         = CancellationToken
                };
                context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault(
                    context.Source,
                    context.Log,
                    context.Token);

                var flatContainer = new FlatContainer(context);

                var packageIndex = new PackageIndex(context);

                // Check packages sequentially: Task.WhenAll caused IO exceptions in Sleet.
                for (int i = packagesToPush.Count - 1; i >= 0; i--)
                {
                    string item = packagesToPush[i];

                    bool?identical = await IsPackageIdenticalOnFeedAsync(
                        item,
                        packageIndex,
                        context.Source,
                        flatContainer,
                        log);

                    if (identical == null)
                    {
                        continue;
                    }

                    packagesToPush.RemoveAt(i);

                    if (identical == true)
                    {
                        Log.LogMessage(
                            MessageImportance.Normal,
                            "Package exists on the feed, and is verified to be identical. " +
                            $"Skipping upload: '{item}'");
                    }
                    else
                    {
                        Log.LogError(
                            "Package exists on the feed, but contents are different. " +
                            $"Upload failed: '{item}'");
                    }
                }

                if (!packagesToPush.Any())
                {
                    Log.LogMessage("After skipping idempotent uploads, no items need pushing.");
                    return(true);
                }
            }

            return(await PushCommand.RunAsync(
                       settings,
                       fileSystem,
                       packagesToPush,
                       options.AllowOverwrite,
                       skipExisting : false,
                       log : log));
        }
Ejemplo n.º 6
0
        private async Task <bool> PushAsync(
            IEnumerable <string> items,
            PushOptions options)
        {
            LocalSettings settings       = GetSettings();
            SleetLogger   log            = new SleetLogger(Log, NuGet.Common.LogLevel.Verbose);
            var           packagesToPush = items.ToList();

            // Create a separate LocalCache to use for read only operations on the feed.
            // Files added to the cache before the lock could be modified by the process
            // currently holding the lock. Sleet assumes that files in the cache
            // are valid and identical to the ones on the feed since operations are
            // normally performed inside the lock.
            using (var preLockCache = CreateFileCache())
            {
                var preLockFileSystem = GetAzureFileSystem(preLockCache);

                if (!options.AllowOverwrite && options.PassIfExistingItemIdentical)
                {
                    var context = new SleetContext
                    {
                        LocalSettings = settings,
                        Log           = log,
                        Source        = preLockFileSystem,
                        Token         = CancellationToken
                    };
                    context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault(
                        context.Source,
                        context.Log,
                        context.Token);

                    var flatContainer = new FlatContainer(context);

                    var packageIndex = new PackageIndex(context);

                    // Check packages sequentially: Task.WhenAll caused IO exceptions in Sleet.
                    for (int i = packagesToPush.Count - 1; i >= 0; i--)
                    {
                        string item = packagesToPush[i];

                        bool?identical = await IsPackageIdenticalOnFeedAsync(
                            item,
                            packageIndex,
                            context.Source,
                            flatContainer,
                            log);

                        if (identical == null)
                        {
                            continue;
                        }

                        packagesToPush.RemoveAt(i);

                        if (identical == true)
                        {
                            Log.LogMessage(
                                MessageImportance.Normal,
                                "Package exists on the feed, and is verified to be identical. " +
                                $"Skipping upload: '{item}'");
                        }
                        else
                        {
                            Log.LogError(
                                "Package exists on the feed, but contents are different. " +
                                $"Upload failed: '{item}'");
                        }
                    }

                    if (!packagesToPush.Any())
                    {
                        Log.LogMessage("After skipping idempotent uploads, no items need pushing.");
                        return(true);
                    }
                }
            }

            // Create a new cache to be used once a lock is obtained.
            using (var fileCache = CreateFileCache())
            {
                var lockedFileSystem = GetAzureFileSystem(fileCache);

                return(await PushCommand.RunAsync(
                           settings,
                           lockedFileSystem,
                           packagesToPush,
                           options.AllowOverwrite,
                           skipExisting : false,
                           log : log));
            }
        }