Esempio n. 1
0
        private async Task DownloadPipelineCacheAsync(
            AgentTaskPluginExecutionContext context,
            DedupManifestArtifactClient dedupManifestClient,
            DedupIdentifier manifestId,
            string targetDirectory,
            string contentFormat,
            CancellationToken cancellationToken)
        {
            if (contentFormat == ContentFormatConstants.SingleTar)
            {
                string manifestPath = Path.Combine(Path.GetTempPath(), $"{nameof(DedupManifestArtifactClient)}.{Path.GetRandomFileName()}.manifest");
                await dedupManifestClient.DownloadFileToPathAsync(manifestId, manifestPath, proxyUri : null, cancellationToken : cancellationToken);

                Manifest manifest = JsonSerializer.Deserialize <Manifest>(File.ReadAllText(manifestPath));
                await TarUtils.DownloadAndExtractTarAsync(context, manifest, dedupManifestClient, targetDirectory, cancellationToken);

                try
                {
                    if (File.Exists(manifestPath))
                    {
                        File.Delete(manifestPath);
                    }
                }
                catch {}
            }
            else
            {
                DownloadDedupManifestArtifactOptions options = DownloadDedupManifestArtifactOptions.CreateWithManifestId(
                    manifestId,
                    targetDirectory,
                    proxyUri: null,
                    minimatchPatterns: null);
                await dedupManifestClient.DownloadAsync(options, cancellationToken);
            }
        }
        private async Task DownloadPipelineCacheAsync(
            AgentTaskPluginExecutionContext context,
            DedupManifestArtifactClient dedupManifestClient,
            DedupIdentifier manifestId,
            string[] pathSegments,
            string workspaceRoot,
            ContentFormat contentFormat,
            CancellationToken cancellationToken)
        {
            if (contentFormat == ContentFormat.SingleTar)
            {
                string manifestPath = Path.Combine(Path.GetTempPath(), $"{nameof(DedupManifestArtifactClient)}.{Path.GetRandomFileName()}.manifest");

                await AsyncHttpRetryHelper.InvokeVoidAsync(
                    async() =>
                {
                    await dedupManifestClient.DownloadFileToPathAsync(manifestId, manifestPath, proxyUri: null, cancellationToken: cancellationToken);
                },
                    maxRetries : 3,
                    tracer : tracer,
                    canRetryDelegate : e => true,
                    context : nameof(DownloadPipelineCacheAsync),
                    cancellationToken : cancellationToken,
                    continueOnCapturedContext : false);

                Manifest manifest = JsonSerializer.Deserialize <Manifest>(File.ReadAllText(manifestPath));
                var(tarWorkingDirectory, _) = GetTarWorkingDirectory(pathSegments, workspaceRoot);
                await TarUtils.DownloadAndExtractTarAsync(context, manifest, dedupManifestClient, tarWorkingDirectory, cancellationToken);

                try
                {
                    if (File.Exists(manifestPath))
                    {
                        File.Delete(manifestPath);
                    }
                }
                catch { }
            }
            else
            {
                DownloadDedupManifestArtifactOptions options = DownloadDedupManifestArtifactOptions.CreateWithManifestId(
                    manifestId,
                    pathSegments[0],
                    proxyUri: null,
                    minimatchPatterns: null);

                await AsyncHttpRetryHelper.InvokeVoidAsync(
                    async() =>
                {
                    await dedupManifestClient.DownloadAsync(options, cancellationToken);
                },
                    maxRetries : 3,
                    tracer : tracer,
                    canRetryDelegate : e => true,
                    context : nameof(DownloadPipelineCacheAsync),
                    cancellationToken : cancellationToken,
                    continueOnCapturedContext : false);
            }
        }
        private async Task <string> GetUploadPathAsync(ContentFormat contentFormat, AgentTaskPluginExecutionContext context, string path, CancellationToken cancellationToken)
        {
            string uploadPath = path;

            if (contentFormat == ContentFormat.SingleTar)
            {
                uploadPath = await TarUtils.ArchiveFilesToTarAsync(context, path, cancellationToken);
            }
            return(uploadPath);
        }
Esempio n. 4
0
        private async Task <string> GetUploadPathAsync(string preferredContentFormat, AgentTaskPluginExecutionContext context, string path, CancellationToken cancellationToken)
        {
            string uploadPath = path;

            if (string.Equals(preferredContentFormat, ContentFormatConstants.SingleTar, StringComparison.OrdinalIgnoreCase))
            {
                uploadPath = await TarUtils.ArchiveFilesToTarAsync(context, path, cancellationToken);
            }
            return(uploadPath);
        }
        private Task <string> GetUploadPathAsync(ContentFormat contentFormat, AgentTaskPluginExecutionContext context, Fingerprint pathFingerprint, string[] pathSegments, string workspaceRoot, CancellationToken cancellationToken)
        {
            if (contentFormat == ContentFormat.SingleTar)
            {
                var(tarWorkingDirectory, isWorkspaceContained) = GetTarWorkingDirectory(pathSegments, workspaceRoot);

                return(TarUtils.ArchiveFilesToTarAsync(
                           context,
                           pathFingerprint,
                           tarWorkingDirectory,
                           isWorkspaceContained,
                           cancellationToken
                           ));
            }

            return(Task.FromResult(pathFingerprint.Segments[0]));
        }