Ejemplo n.º 1
0
        private async Task <IIpcResult> ExecuteGetSealedDirectoryContentAsync(GetSealedDirectoryContentCommand cmd)
        {
            Contract.Requires(cmd != null);

            // for extra safety, check that provided directory path and directory id match
            AbsolutePath dirPath;
            bool         isValidPath = AbsolutePath.TryCreate(m_context.PathTable, cmd.FullDirectoryPath, out dirPath);

            if (!isValidPath || !cmd.Directory.Path.Equals(dirPath))
            {
                return(new IpcResult(
                           IpcResultStatus.ExecutionError,
                           "directory path ids differ, or could not create AbsolutePath; directory = " + cmd.Directory.Path.ToString(m_context.PathTable) + ", directory path = " + cmd.FullDirectoryPath));
            }

            var files = m_fileContentManager.ListSealedDirectoryContents(cmd.Directory);

            Tracing.Logger.Log.ApiServerGetSealedDirectoryContentExecuted(m_loggingContext, cmd.Directory.Path.ToString(m_context.PathTable), files.Length);

            var inputContentsTasks = files
                                     .Select(f => m_fileContentManager.TryQuerySealedOrUndeclaredInputContentAsync(f.Path, nameof(ApiServer), allowUndeclaredSourceReads: true))
                                     .ToArray();

            var inputContents = await TaskUtilities.SafeWhenAll(inputContentsTasks);

            var results       = new List <BuildXL.Ipc.ExternalApi.SealedDirectoryFile>();
            var failedResults = new List <string>();

            for (int i = 0; i < files.Length; ++i)
            {
                // If the content has no value or has unknown length, then we have some inconsistency wrt the sealed directory content
                // Absent files are an exception since it is possible to have sealed directories with absent files (shared opaques is an example of this).
                // In those cases we leave the consumer to deal with them.
                if (!inputContents[i].HasValue || (inputContents[i].Value.Hash != WellKnownContentHashes.AbsentFile && !inputContents[i].Value.HasKnownLength))
                {
                    failedResults.Add(files[i].Path.ToString(m_context.PathTable));
                }
                else
                {
                    results.Add(new BuildXL.Ipc.ExternalApi.SealedDirectoryFile(
                                    files[i].Path.ToString(m_context.PathTable),
                                    files[i],
                                    inputContents[i].Value));
                }
            }

            if (failedResults.Count > 0)
            {
                return(new IpcResult(
                           IpcResultStatus.ExecutionError,
                           string.Format("Could not find content information for {0} out of {1} files inside of '{4}':{2}{3}",
                                         failedResults.Count,
                                         files.Length,
                                         Environment.NewLine,
                                         string.Join("; ", failedResults),
                                         cmd.Directory.Path.ToString(m_context.PathTable))));
            }

            return(IpcResult.Success(cmd.RenderResult(results)));
        }
Ejemplo n.º 2
0
        private async Task <IIpcResult> ExecuteGetSealedDirectoryContent(GetSealedDirectoryContentCommand cmd)
        {
            Contract.Requires(cmd != null);

            // for extra safety, check that provided directory path and directory id match
            AbsolutePath dirPath;
            bool         isValidPath = AbsolutePath.TryCreate(m_context.PathTable, cmd.FullDirectoryPath, out dirPath);

            if (!isValidPath || !cmd.Directory.Path.Equals(dirPath))
            {
                return(new IpcResult(
                           IpcResultStatus.ExecutionError,
                           "directory path ids differ, or could not create AbsolutePath; directory = " + cmd.Directory.Path.ToString(m_context.PathTable) + ", directory path = " + cmd.FullDirectoryPath));
            }

            var files = m_fileContentManager.ListSealedDirectoryContents(cmd.Directory);

            Tracing.Logger.Log.ApiServerGetSealedDirectoryContentExecuted(m_loggingContext, cmd.Directory.Path.ToString(m_context.PathTable), files.Length);

            var inputContentsTasks = files
                                     .Select(f => m_fileContentManager.TryQuerySealedOrUndeclaredInputContentAsync(f.Path, nameof(ApiServer), false))
                                     .ToArray();

            var inputContents = await TaskUtilities.SafeWhenAll(inputContentsTasks);

            var results       = new List <BuildXL.Ipc.ExternalApi.SealedDirectoryFile>();
            var failedResults = new List <string>();

            for (int i = 0; i < files.Length; ++i)
            {
                if (!inputContents[i].HasValue || !inputContents[i].Value.HasKnownLength)
                {
                    failedResults.Add(files[i].Path.ToString(m_context.PathTable));
                }
                else
                {
                    results.Add(new BuildXL.Ipc.ExternalApi.SealedDirectoryFile(
                                    files[i].Path.ToString(m_context.PathTable),
                                    files[i],
                                    inputContents[i].Value));
                }
            }

            if (failedResults.Count > 0)
            {
                return(new IpcResult(
                           IpcResultStatus.ExecutionError,
                           string.Format("Could not find content information for {0} out of {1} files inside of '{4}':{2}{3}",
                                         failedResults.Count,
                                         files.Length,
                                         Environment.NewLine,
                                         string.Join("; ", failedResults),
                                         cmd.Directory.Path.ToString(m_context.PathTable))));
            }

            return(IpcResult.Success(cmd.RenderResult(results)));
        }