PackagePhysicalFileMetadata DownloadPackage( string packageId, IVersion version, Uri feedUri, ICredentials feedCredentials, string cacheDirectory, int maxDownloadAttempts, TimeSpan downloadAttemptBackoff) { Log.Info("Downloading NuGet package {0} v{1} from feed: '{2}'", packageId, version, feedUri); Log.VerboseFormat("Downloaded package will be stored in: '{0}'", cacheDirectory); freeSpaceChecker.EnsureDiskHasEnoughFreeSpace(cacheDirectory); var fullPathToDownloadTo = Path.Combine(cacheDirectory, PackageName.ToCachedFileName(packageId, version, ".nupkg")); var downloader = new InternalNuGetPackageDownloader(fileSystem); downloader.DownloadPackage(packageId, version, feedUri, feedCredentials, fullPathToDownloadTo, maxDownloadAttempts, downloadAttemptBackoff); var pkg = PackagePhysicalFileMetadata.Build(fullPathToDownloadTo); if (pkg == null) { throw new CommandException($"Package metadata for {packageId}, version {version}, could not be determined"); } CheckWhetherThePackageHasDependencies(pkg); return(pkg); }
PackagePhysicalFileMetadata DownloadPackage( string packageId, IVersion version, Uri feedUri, ICredentials feedCredentials, string cacheDirectory, int maxDownloadAttempts, TimeSpan downloadAttemptBackoff) { Log.Info("Downloading GitHub package {0} v{1} from feed: '{2}'", packageId, version, feedUri); Log.VerboseFormat("Downloaded package will be stored in: '{0}'", cacheDirectory); fileSystem.EnsureDirectoryExists(cacheDirectory); freeSpaceChecker.EnsureDiskHasEnoughFreeSpace(cacheDirectory); SplitPackageId(packageId, out var owner, out var repository); if (string.IsNullOrWhiteSpace(owner) || string.IsNullOrWhiteSpace(repository)) { throw new InvalidOperationException( "Invalid PackageId for GitHub feed. Expecting format `<owner>/<repo>`"); } var page = 0; JArray?req = null; while (req == null || req.Count != 0 && req.Count < 1000) { var uri = feedUri.AbsoluteUri + $"repos/{Uri.EscapeUriString(owner)}/{Uri.EscapeUriString(repository)}/tags?page={++page}&per_page=1000"; req = PerformRequest(feedCredentials, uri) as JArray; if (req == null) { break; } foreach (var tag in req) { var v = TryParseVersion((string)tag["name"]); if (v == null || !version.Equals(v)) { continue; } var zipball = (string)tag["zipball_url"]; return(DownloadFile(zipball, cacheDirectory, packageId, version, feedCredentials, maxDownloadAttempts, downloadAttemptBackoff)); } } throw new Exception("Unable to find package {0} v{1} from feed: '{2}'"); }
/// <summary> /// Downloads the artifact from the Maven repo. This method first checks the repo for /// artifacts with all available extensions, as we have no indication what type of artifact /// (jar, war, zip etc) that we are attempting to download. /// </summary> /// <param name="packageId">The package id</param> /// <param name="version">The package version</param> /// <param name="feedUri">The maven repo uri</param> /// <param name="feedCredentials">The mavben repo credentials</param> /// <param name="cacheDirectory">The directory to download the file into</param> /// <param name="maxDownloadAttempts">How many times to try the download</param> /// <param name="downloadAttemptBackoff">How long to wait between attempts</param> /// <returns>The path to the downloaded artifact</returns> PackagePhysicalFileMetadata DownloadPackage( string packageId, IVersion version, Uri feedUri, ICredentials feedCredentials, string cacheDirectory, int maxDownloadAttempts, TimeSpan downloadAttemptBackoff) { Guard.NotNullOrWhiteSpace(packageId, "packageId can not be null"); Guard.NotNull(version, "version can not be null"); Guard.NotNullOrWhiteSpace(cacheDirectory, "cacheDirectory can not be null"); Guard.NotNull(feedUri, "feedUri can not be null"); Log.Info("Downloading Maven package {0} v{1} from feed: '{2}'", packageId, version, feedUri); Log.VerboseFormat("Downloaded package will be stored in: '{0}'", cacheDirectory); freeSpaceChecker.EnsureDiskHasEnoughFreeSpace(cacheDirectory); var mavenPackageId = MavenPackageID.CreatePackageIdFromOctopusInput(packageId, version); var snapshotMetadata = GetSnapshotMetadata(mavenPackageId, feedUri, feedCredentials, maxDownloadAttempts, downloadAttemptBackoff); var found = FirstToRespond(mavenPackageId, feedUri, feedCredentials, snapshotMetadata); Log.VerboseFormat("Found package {0} v{1}", packageId, version); return(DownloadArtifact( found, packageId, version, feedUri, feedCredentials, cacheDirectory, maxDownloadAttempts, downloadAttemptBackoff, snapshotMetadata)); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); string deltaFilePath; string newFilePath; string basisFilePath; try { ValidateParameters(out basisFilePath, out deltaFilePath, out newFilePath); freeSpaceChecker.EnsureDiskHasEnoughFreeSpace(PackageStore.GetPackagesDirectory()); var tempNewFilePath = newFilePath + ".partial"; #if USE_OCTODIFF_EXE var factory = new OctoDiffCommandLineRunner(commandLineRunner); #else var factory = new OctoDiffLibraryCallRunner(); #endif var octoDiff = factory.OctoDiff .Action("patch") .PositionalArgument(basisFilePath) .PositionalArgument(deltaFilePath) .PositionalArgument(tempNewFilePath); if (skipVerification) { octoDiff.Flag("skip-verification"); } if (showProgress) { octoDiff.Flag("progress"); } log.InfoFormat("Applying delta to {0} with hash {1} and storing as {2}", basisFilePath, fileHash, newFilePath); var result = factory.Execute(); if (result.ExitCode != 0) { fileSystem.DeleteFile(tempNewFilePath, FailureOptions.ThrowOnFailure); throw new CommandLineException("OctoDiff", result.ExitCode, result.Errors); } File.Move(tempNewFilePath, newFilePath); if (!File.Exists(newFilePath)) { throw new CommandException($"Failed to apply delta file {deltaFilePath} to {basisFilePath}"); } } catch (Exception e) when(e is CommandLineException || e is CommandException) { log.DeltaVerificationError(e.Message); return(0); } var package = PackagePhysicalFileMetadata.Build(newFilePath); if (package == null) { return(0); } log.DeltaVerification(newFilePath, package.Hash, package.Size); return(0); }