public void DownloadPackage(string packageId, NuGetVersion version, Uri feedUri, ICredentials feedCredentials, string targetFilePath, Action <string, NuGetVersion, Uri, ICredentials, string> action) { while (retry.Try()) { Log.Verbose($"Downloading package (attempt {retry.CurrentTry} of {NumberOfTimesToAttemptToDownloadPackage})"); try { action(packageId, version, feedUri, feedCredentials, targetFilePath); return; } catch (Exception ex) { Log.VerboseFormat("Attempt {0} of {1}: Unable to download package: {2}", retry.CurrentTry, NumberOfTimesToAttemptToDownloadPackage, ex.ToString()); fileSystem.DeleteFile(targetFilePath, FailureOptions.IgnoreFailure); if (retry.CanRetry()) { Thread.Sleep(retry.Sleep()); } else { Log.ErrorFormat("Unable to download package: {0}", ex.Message); throw new Exception( "The package could not be downloaded from NuGet. If you are getting a package verification error, try switching to a Windows File Share package repository to see if that helps."); } } } }
public void DownloadPackage(string packageId, NuGetVersion version, Uri feedUri, ICredentials feedCredentials, string targetFilePath, int maxDownloadAttempts, TimeSpan downloadAttemptBackoff, Action <string, NuGetVersion, Uri, ICredentials, string> action) { if (maxDownloadAttempts <= 0) { throw new ArgumentException($"The number of download attempts should be greater than zero, but was {maxDownloadAttempts}", nameof(maxDownloadAttempts)); } // The RetryTracker is a bit finicky to set up... var numberOfRetriesOnFailure = maxDownloadAttempts - 1; var retry = new RetryTracker(numberOfRetriesOnFailure, timeLimit: null, retryInterval: new LinearRetryInterval(downloadAttemptBackoff)); while (retry.Try()) { Log.Verbose($"Downloading package (attempt {retry.CurrentTry} of {maxDownloadAttempts})"); try { action(packageId, version, feedUri, feedCredentials, targetFilePath); return; } catch (Exception ex) { Log.Verbose($"Attempt {retry.CurrentTry} of {maxDownloadAttempts}: {ex.Message}"); fileSystem.DeleteFile(targetFilePath, FailureOptions.IgnoreFailure); if (retry.CanRetry()) { var wait = TimeSpan.FromMilliseconds(retry.Sleep()); Log.Verbose($"Going to wait {wait.TotalSeconds}s before attempting the download from the external feed again."); Thread.Sleep(wait); } else { var helpfulFailure = $"The package {packageId} version {version} could not be downloaded from the external feed '{feedUri}' after making {maxDownloadAttempts} attempts over a total of {Math.Floor(retry.TotalElapsed.TotalSeconds)}s. Make sure the package is pushed to the external feed and try the deployment again. For a detailed troubleshooting guide go to http://g.octopushq.com/TroubleshootMissingPackages"; helpfulFailure += $"{Environment.NewLine}{ex}"; throw new Exception(helpfulFailure, ex); } } } }
public void LongFilePathsShouldWork() { var paths = new Stack <string>(); var path = rootPath; for (var i = 0; i <= 15; i++) { path += @"\ZZZZabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; fileSystem.EnsureDirectoryExists(path); paths.Push(path); } fileSystem.OverwriteFile("Some sample text", path + @"\test.txt"); fileSystem.DeleteFile(path + @"\test.txt"); while (paths.Any()) { var pathToRemove = paths.Pop(); fileSystem.DeleteDirectory(pathToRemove); } }