/// <summary> /// Exports all implementations listed in a <see cref="Selections"/> document as archives. /// </summary> /// <param name="implementationStore">Used to get cached implementations.</param> /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="IOException">An implementation archive could not be created.</exception> /// <exception cref="UnauthorizedAccessException">Read or access to a file is not permitted.</exception> public void ExportImplementations(IImplementationStore implementationStore, ITaskHandler handler) { #region Sanity checks if (implementationStore == null) { throw new ArgumentNullException(nameof(implementationStore)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } #endregion foreach (var digest in _selections.Implementations.Select(x => x.ManifestDigest).Where(x => x.Best != null).Distinct()) { string?sourcePath = implementationStore.GetPath(digest); if (sourcePath == null) { Log.Warn($"Implementation {digest} missing from cache"); continue; } using var builder = ArchiveBuilder.Create(Path.Combine(_contentDir, digest.Best + ".tgz"), Archive.MimeTypeTarGzip); handler.RunTask(new ReadDirectory(sourcePath, builder)); } }
/// <summary> /// Exports all implementations listed in a <see cref="Selections"/> document as archives. /// </summary> /// <param name="implementationStore">Used to get cached implementations.</param> /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="UnauthorizedAccessException">The file could not be read or written.</exception> /// <exception cref="UnauthorizedAccessException">Write access to the directory is not permitted.</exception> /// <exception cref="IOException">An implementation archive could not be creates.</exception> public void ExportImplementations(IImplementationStore implementationStore, ITaskHandler handler) { if (implementationStore == null) { throw new ArgumentNullException(nameof(implementationStore)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } string contentDir = Path.Combine(_destination, "content"); Directory.CreateDirectory(contentDir); foreach (var digest in _selections.Implementations.Select(x => x.ManifestDigest).Where(x => x.Best != null).Distinct()) { string?sourcePath = implementationStore.GetPath(digest); if (sourcePath == null) { Log.Warn("Implementation " + digest + " missing from cache"); continue; } using var builder = ArchiveBuilder.Create(Path.Combine(contentDir, digest.Best + ".tbz2"), Archive.MimeTypeTarBzip); handler.RunTask(new ReadDirectory(sourcePath, builder)); } }
public override ExitCode Execute() { string outputArchive = AdditionalArgs[1]; string mimeType = (AdditionalArgs.Count == 3) ? AdditionalArgs[3] : Archive.GuessMimeType(outputArchive); var digest = new ManifestDigest(AdditionalArgs[0]); string?sourceDirectory = ImplementationStore.GetPath(digest); if (sourceDirectory == null) { throw new ImplementationNotFoundException(digest); } using var builder = ArchiveBuilder.Create(outputArchive, mimeType); Handler.RunTask(new ReadDirectory(sourceDirectory, builder)); return(ExitCode.OK); }