Ejemplo n.º 1
0
        public void FindPackageById_ReturnsSpecificVersionIfHashFileExists()
        {
            // Arrange
            var fileSystem = new PhysicalFileSystem(tmpDir.Path);

            fileSystem.AddFile(Path.Combine("foo", "1.0.0", "foo.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Foo</id><version>1.0.0</version><authors>None</authors><description>None</description></metadata></package>");

            fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1-345</version><authors>None</authors><description>None</description></metadata></package>");
            fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.1.0.0-beta1-345.nupkg.sha512"), "hash");
            fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.1.0.0-beta1-345.nupkg"), "content");

            fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1</version><authors>test-author</authors><description>None</description></metadata></package>");
            fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.1.0.0-beta1.nupkg.sha512"), "cotnent");
            fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.1.0.0-beta1.nupkg"), "cotnent");

            var repository = new ExpandedPackageRepository(fileSystem);

            // Act
            var package = repository.FindPackage("Bar", NuGetVersion.Parse("1.0.0.0-beta1"));

            // Assert
            Assert.NotNull(package);
            Assert.Equal(SemanticVersion.Parse("1.0.0-beta1"), package.Identity.Version);
            var author = package.Nuspec.GetAuthors();

            Assert.Equal("test-author", author);
        }
Ejemplo n.º 2
0
        public void FindPackageById_ReturnsSpecificVersionIfHashFileExists()
        {
            // Arrange
            var fileSystem = new MockFileSystem();

            fileSystem.AddFile(Path.Combine("Foo", "1.0.0", "Foo.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Foo</id><version>1.0.0</version><authors>None</authors><description>None</description></metadata></package>");

            fileSystem.AddFile(Path.Combine("Bar", "1.0.0-beta1-345", "Bar.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1-345</version><authors>None</authors><description>None</description></metadata></package>");
            fileSystem.AddFile(Path.Combine("Bar", "1.0.0-beta1-345", "Bar.1.0.0-beta1-345.nupkg.sha512"));

            fileSystem.AddFile(Path.Combine("Bar", "1.0.0-beta1", "Bar.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1</version><authors>test-author</authors><description>None</description></metadata></package>");
            fileSystem.AddFile(Path.Combine("Bar", "1.0.0-beta1", "Bar.1.0.0-beta1.nupkg.sha512"));

            var repository = new ExpandedPackageRepository(fileSystem);

            // Act
            var package = repository.FindPackage("Bar", new SemanticVersion("1.0.0.0-beta1"));

            // Assert
            Assert.NotNull(package);
            Assert.Equal(new SemanticVersion("1.0.0-beta1"), package.Version);
            var author = Assert.Single(package.Authors);

            Assert.Equal("test-author", author);
        }
Ejemplo n.º 3
0
        public void Remove(string id, SemanticVersion version, bool enableDelisting)
        {
            if (enableDelisting)
            {
                if (_fileSystem is PhysicalFileSystem physicalFileSystem)
                {
                    var fileName = physicalFileSystem.GetFullPath(
                        GetPackageFileName(id, version.ToNormalizedString()));

                    if (File.Exists(fileName))
                    {
                        File.SetAttributes(fileName, File.GetAttributes(fileName) | FileAttributes.Hidden);
                    }
                    else
                    {
                        _logger.Log(
                            LogLevel.Error,
                            "Error removing package {0} {1} - could not find package file {2}",
                            id,
                            version,
                            fileName);
                    }
                }
            }
            else
            {
                var package = _repository.FindPackage(id, version);

                if (package != null)
                {
                    _repository.RemovePackage(package);
                }
            }
        }
Ejemplo n.º 4
0
        public void FindPackageById_IgnoresVersionsWithoutHashFiles()
        {
            // Arrange
            var fileSystem = new PhysicalFileSystem(tmpDir.Path);

            fileSystem.AddFile(Path.Combine("foo", "1.0.0", "foo.nupkg"), @"Foo.nupkg contents");

            fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1-345</version><authors>None</authors><description>None</description></metadata></package>");

            fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.nuspec"),
                               @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1</version><authors>test-author</authors><description>None</description></metadata></package>");
            var repository = new ExpandedPackageRepository(fileSystem);

            // Act
            var package = repository.FindPackage("Foo", NuGetVersion.Parse("1.0.0"));

            // Assert
            Assert.Null(package);
        }
Ejemplo n.º 5
0
        private void AddPackagesFromDropFolder()
        {
            _logger.Log(LogLevel.Info, "Start adding packages from drop folder.");

            MonitorFileSystem(false);

            try
            {
                var serverPackages = new HashSet <ServerPackage>(PackageEqualityComparer.IdAndVersion);

                foreach (var packageFile in _fileSystem.GetFiles(_fileSystem.Root, "*.nupkg", false))
                {
                    try
                    {
                        // Create package
                        var package = new OptimizedZipPackage(_fileSystem, packageFile);

                        // Is it a symbols package?
                        if (IgnoreSymbolsPackages && package.IsSymbolsPackage())
                        {
                            var message = string.Format(Strings.Error_SymbolsPackagesIgnored, package);

                            _logger.Log(LogLevel.Error, message);

                            continue;
                        }

                        // Allow overwriting package? If not, skip this one.
                        if (!AllowOverrideExistingPackageOnPush && _expandedPackageRepository.FindPackage(package.Id, package.Version) != null)
                        {
                            var message = string.Format(Strings.Error_PackageAlreadyExists, package);

                            _logger.Log(LogLevel.Error, message);

                            continue;
                        }

                        // Copy to correct filesystem location
                        _expandedPackageRepository.AddPackage(package);
                        _fileSystem.DeleteFile(packageFile);

                        // Mark for addition to metadata store
                        serverPackages.Add(CreateServerPackage(package, EnableDelisting));
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        // The file may be in use (still being copied) - ignore the error
                        _logger.Log(LogLevel.Error, "Error adding package file {0} from drop folder: {1}", packageFile, ex.Message);
                    }
                    catch (IOException ex)
                    {
                        // The file may be in use (still being copied) - ignore the error
                        _logger.Log(LogLevel.Error, "Error adding package file {0} from drop folder: {1}", packageFile, ex.Message);
                    }
                }

                // Add packages to metadata store in bulk
                _serverPackageStore.StoreRange(serverPackages);
                _serverPackageStore.PersistIfDirty();

                _logger.Log(LogLevel.Info, "Finished adding packages from drop folder.");
            }
            finally
            {
                OptimizedZipPackage.PurgeCache();

                MonitorFileSystem(true);
            }
        }