/// <summary> /// Returns true if the package is already installed in the local repository. /// </summary> /// <param name="fileSystem">The file system of the local repository.</param> /// <param name="packageId">The package id.</param> /// <param name="version">The package version</param> /// <returns>True if the package is installed in the local repository.</returns> private static bool IsPackageInstalled(IFileSystem fileSystem, string packageId, SemanticVersion version) { if (version != null) { // If we know exactly what package to lookup, check if it's already installed locally. // We'll do this by checking if the package directory exists on disk. var localRepository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem); var packagePaths = localRepository.GetPackageLookupPaths(packageId, version); return packagePaths.Any(fileSystem.FileExists); } return false; }
/// <summary> /// Returns true if the package is already installed in the local repository. /// </summary> /// <param name="fileSystem">The file system of the local repository.</param> /// <param name="packageId">The package id.</param> /// <param name="version">The package version</param> /// <returns>True if the package is installed in the local repository.</returns> private static bool IsPackageInstalled(IFileSystem fileSystem, string packageId, SemanticVersion version) { if (version != null) { // If we know exactly what package to lookup, check if it's already installed locally. // We'll do this by checking if the package directory exists on disk. var localRepository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem); var packagePaths = localRepository.GetPackageLookupPaths(packageId, version); return(packagePaths.Any(fileSystem.FileExists)); } return(false); }
public static bool IsPackageInstalled(this PackageReference packageReference, PhysicalFileSystem fileSystem) { if (packageReference.Version == null) { return(false); } var repository = new LocalPackageRepository(new DefaultPackagePathResolver(fileSystem), fileSystem); return(repository .GetPackageLookupPaths(packageReference.Id, packageReference.Version) .Any()); }
public override async Task <bool> Exists(PackageIdentity identity, bool includeUnlisted, CancellationToken token) { token.ThrowIfCancellationRequested(); bool exists = false; SemanticVersion version = SemanticVersion.Parse(identity.Version.ToString()); if (V2Client is LocalPackageRepository) { LocalPackageRepository lrepo = V2Client as LocalPackageRepository; //Using Path resolver doesnt work. It doesnt consider the subfolders present inside the source directory. Hence using PackageLookupPaths. //return new Uri(Path.Combine(V2Client.Source, lrepo.PathResolver.GetPackageFileName(identity.Id, semVer))); //Using version.ToString() as version.Version gives the normalized string even if the nupkg has unnormalized version in its path. List <string> paths = lrepo.GetPackageLookupPaths(identity.Id, new SemanticVersion(identity.Version.ToString())).ToList(); exists = paths.Any(path => File.Exists(Path.Combine(V2Client.Source, path))); } else if (V2Client is UnzippedPackageRepository) { UnzippedPackageRepository repo = V2Client as UnzippedPackageRepository; // only works for exact version string matches if (repo.Exists(identity.Id, version)) { exists = true; } else { // check for non-exact version string matches exists = repo.FindPackagesById(identity.Id).Any(p => p.Version == version); } } else { // perform a normal exists check exists = V2Client.Exists(identity.Id, version); } return(exists); }
public override async Task <Uri> GetDownloadUrl(PackageIdentity identity, CancellationToken token) { //*TODOs: Temp implementation. Need to do erorr handling and stuff. if (V2Client is DataServicePackageRepository) { if (V2Client.Exists(identity.Id, new SemanticVersion(identity.Version.ToString()))) { //TODOs:Not sure if there is some other standard way to get the Url from a dataservice repo. DataServicePackage has downloadurl property but not sure how to get it. return(new Uri(Path.Combine(V2Client.Source, identity.Id + "." + identity.Version + ".nupkg"))); } else { return(null); } } else if (V2Client is LocalPackageRepository) { LocalPackageRepository lrepo = V2Client as LocalPackageRepository; //Using Path resolver doesnt work. It doesnt consider the subfolders present inside the source directory. Hence using PackageLookupPaths. //return new Uri(Path.Combine(V2Client.Source, lrepo.PathResolver.GetPackageFileName(identity.Id, semVer))); //Using version.ToString() as version.Version gives the normalized string even if the nupkg has unnormalized version in its path. List <string> paths = lrepo.GetPackageLookupPaths(identity.Id, new SemanticVersion(identity.Version.ToString())).ToList(); foreach (var path in paths) { if (File.Exists(Path.Combine(V2Client.Source, path))) { return(new Uri(Path.Combine(V2Client.Source, path))); } } return(null); } else { // TODO: move the string into a resoure file throw new InvalidOperationException(string.Format( CultureInfo.CurrentCulture, "Unable to get download metadata for package {0}", identity.Id)); } }
// Do a very quick check of whether a package in installed by checked whether the nupkg file exists private static bool IsPackageInstalled(LocalPackageRepository packageRepository, IFileSystem fileSystem, string packageId, SemanticVersion version) { var packagePaths = packageRepository.GetPackageLookupPaths(packageId, version); return packagePaths.Any(fileSystem.FileExists); }
// Do a very quick check of whether a package in installed by checked whether the nupkg file exists private static bool IsPackageInstalled(LocalPackageRepository packageRepository, IFileSystem fileSystem, string packageId, SemanticVersion version) { var packagePaths = packageRepository.GetPackageLookupPaths(packageId, version); return(packagePaths.Any(fileSystem.FileExists)); }