/// <summary> /// Exports all implementations listed in a <see cref="Selections"/> document as archives. /// </summary> /// <param name="store">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([NotNull] IStore store, [NotNull] ITaskHandler handler) { #region Sanity checks if (store == null) { throw new ArgumentNullException(nameof(store)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } #endregion 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 = store.GetPath(digest); if (sourcePath == null) { Log.Warn("Implementation " + digest + " missing from cache"); continue; } using (var generator = ArchiveGenerator.Create(sourcePath, Path.Combine(contentDir, digest.Best + ".tbz2"), Archive.MimeTypeTarBzip)) handler.RunTask(generator); } }
/// <summary> /// Creates a archive containing the <see cref="InstallationDir"/>. /// </summary> /// <remarks>Sets <see cref="FeedBuilder.RetrievalMethod"/> and calls <see cref="FeedBuilder.GenerateDigest"/>.</remarks> /// <param name="archivePath">The path of the archive file to create.</param> /// <param name="archiveUrl">The URL where the archive will be uploaded.</param> /// <param name="handler">A callback object used when the the user needs to be informed about IO tasks.</param> /// <exception cref="InvalidOperationException"><see cref="Diff"/> was not called or <see cref="FeedBuilder.MainCandidate"/> is not set.</exception> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="IOException">There was an error reading the installation files or writing the archive.</exception> /// <exception cref="UnauthorizedAccessException">Access to the file system was not permitted.</exception> public void CollectFiles(string archivePath, Uri archiveUrl, ITaskHandler handler) { #region Sanity checks if (string.IsNullOrEmpty(archivePath)) { throw new ArgumentNullException(nameof(archivePath)); } if (archiveUrl == null) { throw new ArgumentNullException(nameof(archiveUrl)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } #endregion if (InstallationDir == null) { throw new InvalidOperationException("Diff() must be called first."); } _feedBuilder.ImplementationDirectory = InstallationDir; _feedBuilder.GenerateDigest(handler); string mimeType = Archive.GuessMimeType(archivePath); using (var generator = ArchiveGenerator.Create(InstallationDir, archivePath, mimeType)) handler.RunTask(generator); _feedBuilder.RetrievalMethod = new Archive { Href = archiveUrl, MimeType = mimeType, Size = new FileInfo(archivePath).Length }; }
private static void GenerateMissingArchive([NotNull] Implementation implementation, [NotNull] ITaskHandler handler, [NotNull] ICommandExecutor executor) { var archive = implementation.RetrievalMethods.OfType <Archive>().SingleOrDefault(); if (archive == null || !string.IsNullOrEmpty(archive.Destination) || !string.IsNullOrEmpty(archive.Extract)) { return; } string directoryPath; string archivePath; try { if (string.IsNullOrEmpty(implementation.LocalPath)) { return; } directoryPath = ModelUtils.GetAbsolutePath(implementation.LocalPath, executor.Path); if (archive.Href == null) { return; } var archiveHref = ModelUtils.GetAbsoluteHref(archive.Href, executor.Path); if (!archiveHref.IsFile) { return; } archivePath = archiveHref.LocalPath; } catch (UriFormatException) { return; } implementation.UpdateDigest(directoryPath, handler, executor); using (var generator = ArchiveGenerator.Create(directoryPath, archivePath, archive.MimeType)) handler.RunTask(generator); executor.Execute(new SetValueCommand <long>(() => archive.Size, x => archive.Size = x, new FileInfo(archivePath).Length)); executor.Execute(new SetValueCommand <string>(() => implementation.LocalPath, x => implementation.LocalPath = x, null)); }
public override ExitCode Execute() { var manifestDigest = new ManifestDigest(AdditionalArgs[0]); string outputArchive = AdditionalArgs[1]; Debug.Assert(outputArchive != null); string sourceDirectory = Store.GetPath(manifestDigest); if (sourceDirectory == null) { throw new ImplementationNotFoundException(manifestDigest); } string mimeType = (AdditionalArgs.Count == 3) ? AdditionalArgs[3] : null; using (var generator = ArchiveGenerator.Create(sourceDirectory, outputArchive, mimeType)) Handler.RunTask(generator); return(ExitCode.OK); }
private static void GenerateMissingArchive(Implementation implementation, ITaskHandler handler, ICommandExecutor executor) { var archive = implementation.RetrievalMethods.OfType <Archive>().FirstOrDefault(); if (archive == null || !string.IsNullOrEmpty(archive.Destination) || !string.IsNullOrEmpty(archive.Extract)) { return; } if (string.IsNullOrEmpty(implementation.LocalPath)) { return; } string directoryPath = ModelUtils.GetAbsolutePath(implementation.LocalPath, executor.Path); if (archive.Href == null) { return; } var archiveHref = ModelUtils.GetAbsoluteHref(archive.Href, executor.Path); if (!archiveHref.IsFile) { return; } implementation.UpdateDigest(directoryPath, handler, executor); using (var generator = ArchiveGenerator.Create( directoryPath, archiveHref.LocalPath, archive.MimeType ?? Archive.GuessMimeType(archiveHref.LocalPath))) handler.RunTask(generator); executor.Execute(SetValueCommand.For(() => archive.Size, newValue: new FileInfo(archiveHref.LocalPath).Length)); executor.Execute(SetValueCommand.For <string?>(() => implementation.LocalPath, newValue: null)); }