public override Task UploadAsync(TransferSpec spec)
 {
     spec.Progress.Tries++;
     ConfirmSchemeSupported(spec.Uri.Scheme);
     return
         (_fileCopy.CopyFileAsync(spec.LocalFile, GetPathFromUri(spec)));
 }
Exemplo n.º 2
0
        static void ProcessExitResult(ProcessExitResultWithOutput result, TransferSpec spec)
        {
            switch (result.ExitCode)
            {
            case 0:
                break;

            case -1:
                throw new RsyncSoftProgramException(
                          $"Aborted/Killed (PID: {result.Id}, Status: {result.ExitCode}). {CreateTransferExceptionMessage(spec)}",
                          result.StandardOutput + result.StandardError, result.StartInfo.Arguments);

            case 35584:
                throw new RsyncSoftProgramException(
                          $"Stackdump (PID: {result.Id}, Status: {result.ExitCode}). {CreateTransferExceptionMessage(spec)}",
                          result.StandardOutput + result.StandardError, result.StartInfo.Arguments);

            case -1073741819:
                throw new RsyncCygwinProgramException(
                          $"Cygwin fork/rebase problem (PID: {result.Id}, Status: {result.ExitCode}). {CreateTransferExceptionMessage(spec)}",
                          result.StandardOutput + result.StandardError, result.StartInfo.Arguments);

            default:
                throw new RsyncException(
                          $"Did not exit gracefully (PID: {result.Id}, Status: {result.ExitCode}). {CreateTransferExceptionMessage(spec)}",
                          result.StandardOutput + result.StandardError, result.StartInfo.Arguments);
            }
        }
        async Task TryDownloadAsync(TransferSpec spec)
        {
            Exception retryEx = null;

            try {
                await base.DownloadAsync(spec).ConfigureAwait(false);
            } catch (ZsyncIncompatibleException e) {
                retryEx = e;
            } catch (ZsyncLoopDetectedException e) {
                retryEx = e;
            } catch (ZsyncCygwinProgramException e) {
                // Rebase issue..
                retryEx = e;
            } catch (ZsyncSoftException e) {
                var progress = spec.Progress;
                if ((progress != null) && !AllowZsyncFallback(progress))
                {
                    throw;
                }
                retryEx = e;
            }
            if (retryEx != null)
            {
                await TryRegularHttpDownloadAsync(spec, retryEx).ConfigureAwait(false);
            }
        }
 public override void Download(TransferSpec spec)
 {
     spec.Progress.Tries++;
     ConfirmSchemeSupported(spec.Uri.Scheme);
     _fileCopy.CopyFile(GetPathFromUri(spec), spec.LocalFile);
     VerifyIfNeeded(spec, spec.LocalFile);
 }
Exemplo n.º 5
0
 public override void Upload(TransferSpec spec)
 {
     spec.Progress.Tries++;
     ConfirmSchemeSupported(spec.Uri.Scheme);
     ProcessExitResult(
         _rsyncLauncher.RunAndProcess(spec.Progress, spec.LocalFile.ToString(), spec.Uri.ToString()), spec);
 }
 private static ZsyncParams GetParams(TransferSpec spec) => new ZsyncParams(spec.Progress,
                                                                            new Uri(FixUrl(spec.Uri)), spec.LocalFile)
 {
     CancelToken  = spec.CancellationToken,
     ExistingFile = spec.ExistingFile,
     Verbose      = Common.Flags.Verbose
 };
Exemplo n.º 7
0
        static async Task TryUploadAsync(TransferSpec spec, IWebClient webClient)
        {
            try {
                if (!string.IsNullOrWhiteSpace(spec.Uri.UserInfo))
                {
                    webClient.SetAuthInfo(spec.Uri);
                }
                using (webClient.HandleCancellationToken(spec))
                    await webClient.UploadFileTaskAsync(spec.Uri, spec.LocalFile.ToString()).ConfigureAwait(false);
            } catch (OperationCanceledException e) {
                throw CreateTimeoutException(spec, e);
            } catch (WebException e) {
                var cancelledEx = e.InnerException as OperationCanceledException;
                if (cancelledEx != null)
                {
                    throw CreateTimeoutException(spec, cancelledEx);
                }
                if (e.Status == WebExceptionStatus.RequestCanceled)
                {
                    throw CreateTimeoutException(spec, e);
                }

                GenerateUploadException(spec, e);
            }
        }
        public override async Task DownloadAsync(TransferSpec spec)
        {
            spec.Progress.Tries++;
            ConfirmSchemeSupported(spec.Uri.Scheme);
            await _fileCopy.CopyFileAsync(GetPathFromUri(spec), spec.LocalFile).ConfigureAwait(false);

            VerifyIfNeeded(spec, spec.LocalFile);
        }
 public override void Download(TransferSpec spec)
 {
     spec.Progress.Tries++;
     ConfirmSchemeSupported(spec.Uri.Scheme);
     spec.Progress.ResetZsyncLoopInfo();
     ProcessExitResult(_zsyncLauncher.RunAndProcess(GetParams(spec)), spec);
     VerifyIfNeeded(spec, spec.LocalFile);
 }
Exemplo n.º 10
0
 public override async Task UploadAsync(TransferSpec spec)
 {
     spec.Progress.Tries++;
     ConfirmSchemeSupported(spec.Uri.Scheme);
     using (var webClient = _webClientFactory())
         using (webClient.Value.SetupUploadTransferProgress(spec.Progress, timeout))
             await TryUploadAsync(spec, webClient.Value).ConfigureAwait(false);
 }
Exemplo n.º 11
0
 protected virtual void TryRegularHttpDownload(TransferSpec spec, Exception exception)
 {
     spec.Progress.Tries++;
     _httpDownloader.Download(new FileDownloadSpec(spec.Uri.ReplaceZsyncProtocol(), spec.LocalFile, spec.Progress)
     {
         CancellationToken = spec.CancellationToken
     });
 }
Exemplo n.º 12
0
 public override async Task DownloadAsync(TransferSpec spec)
 {
     spec.Progress.Tries++;
     ConfirmSchemeSupported(spec.Uri.Scheme);
     spec.Progress.ResetZsyncLoopInfo();
     ProcessExitResult(await _zsyncLauncher.RunAndProcessAsync(GetParams(spec)).ConfigureAwait(false),
                       spec);
     VerifyIfNeeded(spec, spec.LocalFile);
 }
Exemplo n.º 13
0
 public override async Task UploadAsync(TransferSpec spec)
 {
     spec.Progress.Tries++;
     ConfirmSchemeSupported(spec.Uri.Scheme);
     ProcessExitResult(
         await
         _rsyncLauncher.RunAndProcessAsync(spec.Progress, spec.LocalFile.ToString(), spec.Uri.ToString())
         .ConfigureAwait(false), spec);
 }
Exemplo n.º 14
0
 protected override void VerifyIfNeeded(TransferSpec spec, IAbsoluteFilePath localFile)
 {
     // To make sure we dont fall into zsync silent failure trap..
     if (!localFile.Exists)
     {
         throw new ZsyncSoftException("Download failure, file doesn't exist");
     }
     base.VerifyIfNeeded(spec, localFile);
 }
Exemplo n.º 15
0
 public override void Download(TransferSpec spec)
 {
     spec.Progress.Tries++;
     ConfirmSchemeSupported(spec.Uri.Scheme);
     ProcessExitResult(
         _rsyncLauncher.RunAndProcess(spec.Progress, spec.Uri.ToString(), spec.LocalFile.ToString(),
                                      spec.CancellationToken), spec);
     VerifyIfNeeded(spec, spec.LocalFile);
 }
Exemplo n.º 16
0
 protected virtual void VerifyIfNeeded(TransferSpec spec, IAbsoluteFilePath localFile)
 {
     if ((spec.Verification == null) || spec.Verification(localFile))
     {
         return;
     }
     Tools.FileUtil.Ops.DeleteFile(localFile);
     throw new VerificationError(localFile.ToString());
 }
 private void WrapInternal(Action action, TransferSpec spec)
 {
     OnStart(spec);
     try {
         action();
     } catch (Exception e) {
         OnError(spec, e);
         throw;
     }
     OnFinished(spec);
 }
 private async Task WrapInternal(Func <Task> task, TransferSpec spec)
 {
     OnStart(spec);
     try {
         await task().ConfigureAwait(false);
     } catch (Exception e) {
         OnError(spec, e);
         throw;
     }
     OnFinished(spec);
 }
Exemplo n.º 19
0
 public override async Task DownloadAsync(TransferSpec spec)
 {
     spec.Progress.Tries++;
     ConfirmSchemeSupported(spec.Uri.Scheme);
     ProcessExitResult(
         await
         _rsyncLauncher.RunAndProcessAsync(spec.Progress, spec.Uri.ToString(), spec.LocalFile.ToString(),
                                           spec.CancellationToken)
         .ConfigureAwait(false), spec);
     VerifyIfNeeded(spec, spec.LocalFile);
 }
 protected void Wrap(Action action, TransferSpec spec)
 {
     if (Common.Flags.Verbose)
     {
         WrapInternal(action, spec);
     }
     else
     {
         action();
     }
 }
Exemplo n.º 21
0
        protected override void OnError(TransferSpec spec, Exception e)
        {
            var msg = $"Failed upload of {spec.LocalFile} to {spec.Uri} ({e.Message})";

            if (spec.Progress.Tries <= 1)
            {
                this.Logger().Error(msg);
            }
            else
            {
                this.Logger().Warn(msg);
            }
        }
Exemplo n.º 22
0
        void LogMessage(TransferSpec spec, Exception e)
        {
            var    tfex = e as DownloadException;
            string o    = null;

            if (tfex != null)
            {
                o = "\nOutput: " + tfex.Output;
            }
            this.Logger()
            .Warn("Performing http fallback for {0} due to {1} ({2}){3}", spec.Uri.AuthlessUri(), e.GetType(),
                  e.Message, o);
        }
Exemplo n.º 23
0
        async Task TryDownloadAsync(TransferSpec spec, IWebClient webClient, IAbsoluteFilePath tmpFile)
        {
            try {
                tmpFile.RemoveReadonlyWhenExists();
                if (!string.IsNullOrWhiteSpace(spec.Uri.UserInfo))
                {
                    webClient.SetAuthInfo(spec.Uri);
                }
                using (webClient.HandleCancellationToken(spec))
                    await webClient.DownloadFileTaskAsync(spec.Uri, tmpFile.ToString()).ConfigureAwait(false);
                VerifyIfNeeded(spec, tmpFile);
                _fileOps.Move(tmpFile, spec.LocalFile);
            } catch (OperationCanceledException e) {
                _fileOps.DeleteIfExists(tmpFile.ToString());
                throw CreateTimeoutException(spec, e);
            } catch (WebException ex) {
                _fileOps.DeleteIfExists(tmpFile.ToString());
                var cancelledEx = ex.InnerException as OperationCanceledException;
                if (cancelledEx != null)
                {
                    throw CreateTimeoutException(spec, cancelledEx);
                }
                if (ex.Status == WebExceptionStatus.RequestCanceled)
                {
                    throw CreateTimeoutException(spec, ex);
                }

                var response = ex.Response as HttpWebResponse;
                if (response == null)
                {
                    throw GenerateDownloadException(spec, ex);
                }

                switch (response.StatusCode)
                {
                case HttpStatusCode.NotFound:
                    throw new RequestFailedException("Received a 404: NotFound response", ex);

                case HttpStatusCode.Forbidden:
                    throw new RequestFailedException("Received a 403: Forbidden response", ex);

                case HttpStatusCode.Unauthorized:
                    throw new RequestFailedException("Received a 401: Unauthorized response", ex);
                }
                throw GenerateDownloadException(spec, ex);
            }
        }
Exemplo n.º 24
0
 void TryDownload(TransferSpec spec)
 {
     try {
         base.Download(spec);
     } catch (ZsyncIncompatibleException e) {
         TryRegularHttpDownload(spec, e);
     } catch (ZsyncLoopDetectedException e) {
         TryRegularHttpDownload(spec, e);
     } catch (ZsyncSoftException e) {
         var progress = spec.Progress;
         if ((progress != null) && !AllowZsyncFallback(progress))
         {
             throw;
         }
         TryRegularHttpDownload(spec, e);
     }
 }
        protected override void OnError(TransferSpec spec, Exception e)
        {
            if (e is OperationCanceledException)
            {
                this.Logger()
                .Warn(
                    $"Cancelled download of {spec.Uri} to {spec.LocalFile}, try {spec.Progress.Tries} ({e.Message})");
                return;
            }
            var msg =
                $"Failed download of {spec.Uri} to {spec.LocalFile}, try {spec.Progress.Tries} ({e.Message})\nOutput: {spec.Progress.Output}\n\nError report: {e.Format(1)}";

            if (spec.Progress.Tries > 1)
            {
                this.Logger().Warn(msg);
            }
            else
            {
                this.Logger().Error(msg);
            }
        }
Exemplo n.º 26
0
        static void GenerateUploadException(TransferSpec spec, WebException e)
        {
            // TODO: Or should we rather abstract this away into the downloader exceptions instead?
            var r = e.Response as HttpWebResponse;

            if (r != null)
            {
                throw new HttpUploadException(e.Message + ". " + CreateTransferExceptionMessage(spec), e)
                      {
                          StatusCode = r.StatusCode
                      };
            }

            /*
             * var r2 = e.Response as FtpWebResponse;
             * if (r2 != null) {
             *  throw new FtpUploadException(e.Message + ". " + CreateTransferExceptionMessage(spec), e) {
             *      StatusCode = r2.StatusCode
             *  };
             * }
             */
            throw new UploadException(e.Message + ". " + CreateTransferExceptionMessage(spec), e);
        }
Exemplo n.º 27
0
 protected override void OnFinished(TransferSpec spec)
 {
     this.Logger().Info("Finished upload of {0} to {1}", spec.LocalFile, spec.Uri);
 }
Exemplo n.º 28
0
 public override Task DownloadAsync(TransferSpec spec) => TryDownloadAsync(spec);
Exemplo n.º 29
0
 protected override Task TryRegularHttpDownloadAsync(TransferSpec spec, Exception e)
 {
     LogMessage(spec, e);
     return(base.TryRegularHttpDownloadAsync(spec, e));
 }
Exemplo n.º 30
0
 protected override void TryRegularHttpDownload(TransferSpec spec, Exception e)
 {
     LogMessage(spec, e);
     base.TryRegularHttpDownload(spec, e);
 }