Exemplo n.º 1
0
        /// <summary>
        /// This will download the dedup into stdin stream while extracting the TAR simulataneously (piped). This is done by
        /// starting the download through a Task and starting the TAR/7z process which is reading from STDIN.
        /// </summary>
        /// <remarks>
        /// Windows will use 7z to extract the TAR file (only if 7z is installed on the machine and is part of PATH variables).
        /// Non-Windows machines will extract TAR file using the 'tar' command'.
        /// </remarks>
        public static Task DownloadAndExtractTarAsync(
            AgentTaskPluginExecutionContext context,
            Manifest manifest,
            DedupManifestArtifactClient dedupManifestClient,
            string tarWorkingDirectory,
            CancellationToken cancellationToken)
        {
            ValidateTarManifest(manifest);

            DedupIdentifier dedupId = DedupIdentifier.Create(manifest.Items.Single(i => i.Path.EndsWith(archive, StringComparison.OrdinalIgnoreCase)).Blob.Id);

            // We now can simply specify the working directory as the tarball will contain paths relative to it
            ProcessStartInfo processStartInfo = GetExtractStartProcessInfo(context, tarWorkingDirectory);

            if (!Directory.Exists(tarWorkingDirectory))
            {
                Directory.CreateDirectory(tarWorkingDirectory);
            }

            Func <Process, CancellationToken, Task> downloadTaskFunc =
                (process, ct) =>
                Task.Run(async() =>
            {
                try
                {
                    await dedupManifestClient.DownloadToStreamAsync(dedupId, process.StandardInput.BaseStream, proxyUri: null, cancellationToken: ct);
                    process.StandardInput.BaseStream.Close();
                }
                catch (Exception e)
                {
                    try
                    {
                        process.Kill();
                    }
                    catch { }
                    ExceptionDispatchInfo.Capture(e).Throw();
                }
            });

            return(RunProcessAsync(
                       context,
                       processStartInfo,
                       downloadTaskFunc,
                       () => { },
                       cancellationToken));
        }
Exemplo n.º 2
0
        /// <summary>
        /// This will download the dedup into stdin stream while extracting the TAR simulataneously (piped). This is done by
        /// starting the download through a Task and starting the TAR/7z process which is reading from STDIN.
        /// </summary>
        /// <remarks>
        /// Windows will use 7z to extract the TAR file (only if 7z is installed on the machine and is part of PATH variables).
        /// Non-Windows machines will extract TAR file using the 'tar' command'.
        /// </remarks>
        public static Task DownloadAndExtractTarAsync(
            AgentTaskPluginExecutionContext context,
            Manifest manifest,
            DedupManifestArtifactClient dedupManifestClient,
            string targetDirectory,
            CancellationToken cancellationToken)
        {
            ValidateTarManifest(manifest);

            Directory.CreateDirectory(targetDirectory);

            DedupIdentifier dedupId          = DedupIdentifier.Create(manifest.Items.Single(i => i.Path == $"/{archiveFileName}").Blob.Id);
            bool            does7zExists     = isWindows ? CheckIf7ZExists() : false;
            string          processFileName  = (does7zExists) ? "7z" : "tar";
            string          processArguments = (does7zExists) ? $"x -si -aoa -o{targetDirectory} -ttar" : $"-xf - -C {targetDirectory}";

            Func <Process, CancellationToken, Task> downloadTaskFunc =
                (process, ct) =>
                Task.Run(async() => {
                try
                {
                    await dedupManifestClient.DownloadToStreamAsync(dedupId, process.StandardInput.BaseStream, proxyUri: null, cancellationToken: ct);
                    process.StandardInput.BaseStream.Close();
                }
                catch (Exception e)
                {
                    process.Kill();
                    ExceptionDispatchInfo.Capture(e).Throw();
                }
            });

            return(RunProcessAsync(
                       context,
                       processFileName,
                       processArguments,
                       downloadTaskFunc,
                       () => { },
                       cancellationToken));
        }