/// <summary> /// Deletes a package from the store. /// </summary> /// <param name="packageId">The ID of the package to delete.</param> /// <param name="packageVersion">The version of the package to delete.</param> /// <exception cref="ArgumentNullException"><paramref name="packageId"/> is null or contains only whitespace or <paramref name="packageVersion"/> is null.</exception> public override void DeletePackage(string packageId, SemanticVersion packageVersion) { if (string.IsNullOrWhiteSpace(packageId)) { throw new ArgumentNullException("packageId"); } if (packageVersion == null) { throw new ArgumentNullException("packageVersion"); } InitPackageStore(); _logger.Debug("DeletePackage('" + packageId + "', '" + packageVersion + "') called"); var packagePath = Path.Combine(RootPath, packageId); if (_fileSystemOperations.DirectoryExists(packagePath)) { var versionPath = Path.Combine(packagePath, packageId + "." + packageVersion + ".nupkg"); _logger.Debug("Deleting file '" + versionPath + "'."); try { _fileSystemOperations.DeleteFile(versionPath); } catch (Exception ex) { _logger.Error(string.Format("Error deleting package '{0}', version '{1}'", packageId, packageVersion), ex); throw; } if (!_fileSystemOperations.EnumerateFileSystemEntries(packagePath).Any()) { _logger.Debug("Deleting folder '" + packagePath + "'."); try { _fileSystemOperations.DeleteDirectory(packagePath); } catch (Exception ex) { _logger.Warn(string.Format("Exception while attemptnig to delete folder '{0}')", packagePath), ex); } } } else { _logger.WarnFormat("Attempted to delete pacakage ('{0}', '{1}') that didn't exist ", packageId, packageVersion); } }