/// <nodoc /> private async Task <EvaluationResult> ValidateAndStoreIncrementalExtractState(PipConstructionHelper pipConstructionHelper, DownloadData downloadData) { var archive = downloadData.DownloadedFilePath.ToString(m_context.PathTable); var target = downloadData.ContentsFolder.Path.ToString(m_context.PathTable); try { var allFiles = new List <FileArtifact>(); var enumeratResult = FileUtilities.EnumerateDirectoryEntries(target, true, "*", (dir, fileName, attributes) => { if ((attributes & FileAttributes.Directory) == 0) { var filePath = Path.Combine(dir, fileName); allFiles.Add(FileArtifact.CreateSourceFile(AbsolutePath.Create(m_context.PathTable, filePath))); } }); if (!enumeratResult.Succeeded) { var error = new Win32Exception(enumeratResult.NativeErrorCode); m_logger.ErrorListingPackageContents(m_context.LoggingContext, downloadData.Settings.ModuleName, archive, target, error.Message); return(EvaluationResult.Error); } if (allFiles.Count == 0) { m_logger.ErrorListingPackageContents(m_context.LoggingContext, downloadData.Settings.ModuleName, archive, target, "file list is empty"); return(EvaluationResult.Error); } var sortedFiles = SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .CloneAndSort( allFiles, OrdinalFileArtifactComparer.Instance); var hashes = new Dictionary <AbsolutePath, ContentHash>(); foreach (var file in allFiles) { var hash = await GetContentHashAsync(file); hashes.Add(file.Path, hash); } var incrementalState = new ExtractIncrementalState(downloadData, sortedFiles, hashes); await incrementalState.SaveAsync(m_context); return(SealDirectory(pipConstructionHelper, downloadData, downloadData.ContentsFolder, sortedFiles)); } catch (Exception e) when(e is BuildXLException || e is IOException || e is UnauthorizedAccessException) { m_logger.ErrorExtractingArchive(m_context.LoggingContext, downloadData.Settings.ModuleName, archive, target, e.Message); return(EvaluationResult.Error); } }
private EvaluationResult SealDirectoryHelper(Context context, ModuleLiteral env, EvaluationStackFrame args, SealDirectoryKind sealDirectoryKind) { AbsolutePath path; ArrayLiteral contents; string[] tags; string description; bool scrub; if (args.Length > 0 && args[0].Value is ObjectLiteral) { var obj = Args.AsObjectLiteral(args, 0); var directory = Converter.ExtractDirectory(obj, m_sealRoot, allowUndefined: false); path = directory.Path; contents = Converter.ExtractArrayLiteral(obj, m_sealFiles, allowUndefined: false); tags = Converter.ExtractStringArray(obj, m_sealTags, allowUndefined: true); description = Converter.ExtractString(obj, m_sealDescription, allowUndefined: true); scrub = sealDirectoryKind.IsFull() ? Converter.ExtractOptionalBoolean(obj, m_sealScrub) ?? false : false; } else { path = Args.AsPath(args, 0, false); contents = Args.AsArrayLiteral(args, 1); tags = Args.AsStringArrayOptional(args, 2); description = Args.AsStringOptional(args, 3); // Only do scrub for fully seal directory scrub = sealDirectoryKind.IsFull() ? Args.AsBoolOptional(args, 4) : false; } var fileContents = new FileArtifact[contents.Length]; for (int i = 0; i < contents.Length; ++i) { fileContents[i] = Converter.ExpectFile(contents[i], strict: false, context: new ConversionContext(pos: i, objectCtx: contents)); } var sortedFileContents = SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .CloneAndSort(fileContents, OrdinalFileArtifactComparer.Instance); DirectoryArtifact sealedDirectoryArtifact; if (!context.GetPipConstructionHelper().TrySealDirectory(path, sortedFileContents, sealDirectoryKind, tags, description, null, out sealedDirectoryArtifact, scrub)) { // Error has been logged return(EvaluationResult.Error); } var result = new StaticDirectory(sealedDirectoryArtifact, sealDirectoryKind, sortedFileContents.WithCompatibleComparer(OrdinalPathOnlyFileArtifactComparer.Instance)); return(new EvaluationResult(result)); }
private static SealDirectory CreateSeal(TestEnv env, AbsolutePath path, bool partial, FileArtifact[] contents) { var seal = new SealDirectory( path, SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .CloneAndSort(contents, OrdinalFileArtifactComparer.Instance), kind: partial ? SealDirectoryKind.Partial : SealDirectoryKind.Full, provenance: env.CreatePipProvenance(StringId.Invalid), tags: ReadOnlyArray <StringId> .Empty, patterns: ReadOnlyArray <StringId> .Empty); env.PipTable.Add(((PipGraph.Builder)(env.PipGraph)).MutableDataflowGraph.CreateNode().Value, seal); return(seal); }
private EvaluationResult EnsureContents(Context context, StaticDirectory receiver, EvaluationResult arg, EvaluationStackFrame captures) { // Check the kind. For now this only works on Full and Partial Sealed directories // This needs to be extended (just like getFile and getFiles) to opaque and sourcesealed directories. var stringTable = context.FrontEndContext.StringTable; var pathTable = context.FrontEndContext.PathTable; switch (receiver.SealDirectoryKind) { case SealDirectoryKind.Full: case SealDirectoryKind.Partial: // Supported since we have static directory. break; default: // For the other types we will need to schedule a pip in the graph that actually validates at runtime the file is there // either on disk for sourcesealed, or in the opaque collection by using FileContentManager.ListSealedDirectoryContents throw new DirectoryNotSupportedException(receiver.Root.Path.ToString(pathTable)); } var obj = Converter.ExpectObjectLiteral(arg); var subFolder = Converter.ExtractRelativePath(obj, m_subFolder); var filterPath = receiver.Root.Path.Combine(pathTable, subFolder); var fileContents = new List <FileArtifact>(); foreach (var sealedFile in receiver.Contents) { if (sealedFile.Path.IsWithin(pathTable, filterPath)) { fileContents.Add(sealedFile); } } var sortedFileContents = SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .CloneAndSort(fileContents, OrdinalFileArtifactComparer.Instance); if (!context.GetPipConstructionHelper().TrySealDirectory(filterPath, sortedFileContents, SealDirectoryKind.Partial, null, null, null, out var sealedDirectoryArtifact, false)) { // Error has been logged return(EvaluationResult.Error); } var result = new StaticDirectory(sealedDirectoryArtifact, SealDirectoryKind.Partial, sortedFileContents.WithCompatibleComparer(OrdinalPathOnlyFileArtifactComparer.Instance)); return(EvaluationResult.Create(result)); }
/// <inheritdoc/> public SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> ListSealDirectoryContents(DirectoryArtifact directory) { return(SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .CloneAndSort(m_inputContent, OrdinalFileArtifactComparer.Instance)); }
/// <inheritdoc/> public SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> ListSealDirectoryContents(DirectoryArtifact directory, out IReadOnlySet <AbsolutePath> temporaryFiles) { temporaryFiles = CollectionUtilities.EmptySet <AbsolutePath>(); return(SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .CloneAndSort(m_inputContent, OrdinalFileArtifactComparer.Instance)); }