Пример #1
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);
                }
            }
        }
Пример #2
0
        public void RemovePackage_Succeeds_IfPackageDoesNotExist()
        {
            // Arrange
            var fileSystem = new MockFileSystem();

            fileSystem.AddFile(Path.Combine("Foo", "1.0.0", "Foo.nuspec"), "Nuspec contents");
            fileSystem.AddFile(Path.Combine("Foo", "1.0.0", "tools", "net45", "Foo.targets"), "Foo.targets contents");
            fileSystem.AddFile(Path.Combine("Foo", "1.0.0-beta4", "Foo.nupkg"), "1.0.0-beta4 Nuspec contents");

            var repository = new ExpandedPackageRepository(fileSystem);
            var package    = PackageUtility.CreatePackage("Foo", "1.0.0-beta4");

            // Act
            repository.RemovePackage(package);

            // Assert
            Assert.Empty(fileSystem.Deleted);
        }
Пример #3
0
        public void RemovePackage_DeletesPackageDirectory_IfItExists()
        {
            // Arrange
            var fileSystem = new MockFileSystem();

            fileSystem.AddFile(Path.Combine("Foo", "1.0.0-beta2", "Foo.nuspec"), "Nuspec contents");
            fileSystem.AddFile(Path.Combine("Foo", "1.0.0-beta2", "Foo.1.0.0-beta2.nupkg.sha512"), "hash contents");
            fileSystem.AddFile(Path.Combine("Foo", "1.0.0-beta2", "tools", "net45", "Foo.targets"), "Foo.targets contents");
            fileSystem.AddFile(Path.Combine("Foo", "1.0.0-beta4", "Foo.nuspec"), "1.0.0-beta4 Nuspec contents");

            var repository = new ExpandedPackageRepository(fileSystem);
            var package    = PackageUtility.CreatePackage("Foo", "1.0-beta2");

            // Act
            repository.RemovePackage(package);

            // Assert
            var deletedItems = Assert.Single(fileSystem.Deleted);

            Assert.Contains(Path.Combine("Foo", "1.0.0-beta2"), deletedItems);
            Assert.True(fileSystem.FileExists(Path.Combine("Foo", "1.0.0-beta4", "Foo.nuspec")));
        }
Пример #4
0
        /// <summary>
        /// Unlist or delete a package.
        /// </summary>
        public override void RemovePackage(IPackage package)
        {
            if (package != null)
            {
                MonitorFileSystem(false);
                try
                {
                    lock (_syncLock)
                    {
                        _logger.Log(LogLevel.Info, "Start removing package {0} {1}.", package.Id, package.Version);

                        if (EnableDelisting)
                        {
                            var physicalFileSystem = _fileSystem as PhysicalFileSystem;
                            if (physicalFileSystem != null)
                            {
                                var fileName = physicalFileSystem.GetFullPath(
                                    GetPackageFileName(package.Id, package.Version));

                                if (File.Exists(fileName))
                                {
                                    // Set "unlisted"
                                    File.SetAttributes(fileName, File.GetAttributes(fileName) | FileAttributes.Hidden);

                                    // Update metadata store
                                    var serverPackage = FindPackage(package.Id, package.Version) as ServerPackage;
                                    if (serverPackage != null)
                                    {
                                        serverPackage.Listed = false;
                                        _serverPackageStore.Store(serverPackage);
                                    }

                                    // Note that delisted files can still be queried, therefore not deleting persisted hashes if present.
                                    // Also, no need to flip hidden attribute on these since only the one from the nupkg is queried.

                                    _logger.Log(LogLevel.Info, "Unlisted package {0} {1}.", package.Id, package.Version);
                                }
                                else
                                {
                                    _logger.Log(LogLevel.Error,
                                                "Error removing package {0} {1} - could not find package file {2}",
                                                package.Id, package.Version, fileName);
                                }
                            }
                        }
                        else
                        {
                            // Remove from filesystem
                            _expandedPackageRepository.RemovePackage(package);

                            // Update metadata store
                            _serverPackageStore.Remove(package.Id, package.Version);

                            _logger.Log(LogLevel.Info, "Finished removing package {0} {1}.", package.Id, package.Version);
                        }
                    }
                }
                finally
                {
                    MonitorFileSystem(true);
                }
            }
        }