コード例 #1
0
        private async Task <bool> InstallPackageAsync(RemoteMatch installItem, NuGetv3LocalRepository userPackageFolder, PackageExtractionContext packageExtractionContext, CancellationToken token)
        {
            var packageIdentity = new PackageIdentity(installItem.Library.Name, installItem.Library.Version);

            // Check if the package has already been installed.
            if (!userPackageFolder.Exists(packageIdentity.Id, packageIdentity.Version))
            {
                var versionFolderPathResolver = new VersionFolderPathResolver(_request.PackagesDirectory);

                try
                {
                    using (var packageDependency = await installItem.Provider.GetPackageDownloaderAsync(
                               packageIdentity,
                               _request.CacheContext,
                               _logger,
                               token))
                    {
                        // Install, returns true if the package was actually installed.
                        // Returns false if the package was a noop once the lock
                        // was acquired.
                        var installed = await PackageExtractor.InstallFromSourceAsync(
                            packageIdentity,
                            packageDependency,
                            versionFolderPathResolver,
                            packageExtractionContext,
                            token,
                            ParentId);

                        // 1) If another project in this process installs the package this will return false but userPackageFolder will contain the package.
                        // 2) If another process installs the package then this will also return false but we still need to update the cache.
                        // For #2 double check that the cache has the package now otherwise clear
                        if (installed || !userPackageFolder.Exists(packageIdentity.Id, packageIdentity.Version))
                        {
                            // If the package was added, clear the cache so that the next caller can see it.
                            // Avoid calling this for packages that were not actually installed.
                            userPackageFolder.ClearCacheForIds(new string[] { packageIdentity.Id });
                        }
                    }
                }
                catch (SignatureException e)
                {
                    if (!string.IsNullOrEmpty(e.Message))
                    {
                        await _logger.LogAsync(e.AsLogMessage());
                    }

                    // If the package is unsigned and unsigned packages are not allowed a SignatureException
                    // will be thrown but it won't have results because it didn't went through any
                    // verification provider.
                    if (e.Results != null)
                    {
                        await _logger.LogMessagesAsync(e.Results.SelectMany(p => p.Issues));
                    }

                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        public async Task <LocalPackageSourceInfo> EnsureLocalPackage(IRemoteDependencyProvider provider,
                                                                      PackageIdentity packageIdentity)
        {
            if (!_v3LocalRepository.Exists(packageIdentity.Id, packageIdentity.Version))
            {
                var packageDependency = await provider.GetPackageDownloaderAsync(packageIdentity, _cache, _context.Logger, CancellationToken.None);

                var installed = await PackageExtractor.InstallFromSourceAsync(
                    packageIdentity,
                    packageDependency,
                    _v3LocalRepository.PathResolver,
                    _context,
                    CancellationToken.None,
                    Guid.NewGuid());

                // 1) If another project in this process installs the package this will return false but userPackageFolder will contain the package.
                // 2) If another process installs the package then this will also return false but we still need to update the cache.
                // For #2 double check that the cache has the package now otherwise clear
                if (installed || !_v3LocalRepository.Exists(packageIdentity.Id, packageIdentity.Version))
                {
                    // If the package was added, clear the cache so that the next caller can see it.
                    // Avoid calling this for packages that were not actually installed.
                    _v3LocalRepository.ClearCacheForIds(new string[] { packageIdentity.Id });
                }
            }

            return(NuGetv3LocalRepositoryUtility.GetPackage(new[] { _v3LocalRepository }, packageIdentity.Id, packageIdentity.Version));
        }
コード例 #3
0
        public async Task NuGetv3LocalRepository_Exists_DoesNotExist()
        {
            using (var workingDir = TestDirectory.Create())
            {
                var target = new NuGetv3LocalRepository(workingDir);
                await SimpleTestPackageUtility.CreateFolderFeedV3(
                    workingDir,
                    PackageSaveMode.Defaultv3,
                    new SimpleTestPackageContext("foo", "1.0.0"));

                target.Exists("foo", NuGetVersion.Parse("2.0.0")).Should().BeFalse();
                target.Exists("bar", NuGetVersion.Parse("1.0.0")).Should().BeFalse();
            }
        }
コード例 #4
0
        public async Task NuGetv3LocalRepository_Exists_WorksForAllCases(string id)
        {
            using (var workingDir = TestDirectory.Create())
            {
                var target = new NuGetv3LocalRepository(workingDir);
                await SimpleTestPackageUtility.CreateFolderFeedV3(
                    workingDir,
                    PackageSaveMode.Defaultv3,
                    new SimpleTestPackageContext("foo", "1.0.0"));

                target.Exists(id, NuGetVersion.Parse("1.0.0")).Should().BeTrue();
            }
        }
コード例 #5
0
        public async Task NuGetv3LocalRepository_GenerateNupkgMetadataFile()
        {
            using (var workingDir = TestDirectory.Create())
            {
                var target = new NuGetv3LocalRepository(workingDir);
                await SimpleTestPackageUtility.CreateFolderFeedV3Async(
                    workingDir,
                    PackageSaveMode.Defaultv3,
                    new SimpleTestPackageContext("foo", "1.0.0"));

                var pathResolver = new VersionFolderPathResolver(workingDir);

                File.Delete(pathResolver.GetNupkgMetadataPath("foo", new NuGetVersion("1.0.0")));

                // Assert
                target.Exists("foo", NuGetVersion.Parse("1.0.0")).Should().BeTrue();
                File.Exists(pathResolver.GetNupkgMetadataPath("foo", new NuGetVersion("1.0.0")));
            }
        }
コード例 #6
0
        private async Task InstallPackageAsync(RemoteMatch installItem, NuGetv3LocalRepository userPackageFolder, CancellationToken token)
        {
            var packageIdentity = new PackageIdentity(installItem.Library.Name, installItem.Library.Version);

            // Check if the package has already been installed.
            if (!userPackageFolder.Exists(packageIdentity.Id, packageIdentity.Version))
            {
                var versionFolderPathContext = new VersionFolderPathContext(
                    packageIdentity,
                    _request.PackagesDirectory,
                    _logger,
                    _request.PackageSaveMode,
                    _request.XmlDocFileSaveMode);

                using (var packageDependency = await installItem.Provider.GetPackageDownloaderAsync(
                           packageIdentity,
                           _request.CacheContext,
                           _logger,
                           token))
                {
                    // Install, returns true if the package was actually installed.
                    // Returns false if the package was a noop once the lock
                    // was acquired.
                    var installed = await PackageExtractor.InstallFromSourceAsync(
                        packageDependency,
                        versionFolderPathContext,
                        token);

                    if (installed)
                    {
                        // If the package was added, clear the cache so that the next caller can see it.
                        // Avoid calling this for packages that were not actually installed.
                        userPackageFolder.ClearCacheForIds(new string[] { packageIdentity.Id });
                    }
                }
            }
        }