Example #1
0
        /// <summary>
        /// Checks that
        ///   - a sideband file for a given process exists
        ///   - the sideband file is not corrupt (its checksum checks out)
        ///   - the process metadata recorded in the sideband file matches the metadata expected for this process
        /// </summary>
        private bool ValidateSidebandFileForProcess(Process process)
        {
            var sidebandFile = GetSidebandFile(process);

            if (!FileUtilities.FileExistsNoFollow(sidebandFile))
            {
                return(failed(SidebandIntegrityCheckFailReason.FileNotFound));
            }

            using (var reader = new SidebandReader(sidebandFile))
            {
                if (!reader.ReadHeader(ignoreChecksum: false))
                {
                    return(failed(SidebandIntegrityCheckFailReason.ChecksumMismatch));
                }

                var metadata = reader.ReadMetadata();
                var expected = PipExecutor.CreateSidebandMetadata(Scheduler, process);
                if (!metadata.Equals(expected))
                {
                    return(failed(SidebandIntegrityCheckFailReason.MetadataMismatch, $"Expected: {expected}.  Actual: {metadata}"));
                }

                return(true);
            }

            bool failed(SidebandIntegrityCheckFailReason reason, string details = "")
            {
                Logger.Log.SidebandIntegrityCheckForProcessFailed(LoggingContext, process.FormattedSemiStableHash, sidebandFile, reason.ToString(), details);
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Checks that
        ///   - a sideband file for a given process exists
        ///   - the sideband file is not corrupt (its checksum checks out)
        ///   - the process metadata recorded in the sideband file matches the metadata expected for this process
        /// Returns true on success and the sideband state in the out parameter
        /// </summary>
        private bool TryGetAndValidateSidebandStateForProcess(Process process, out IReadOnlyCollection <AbsolutePath> paths)
        {
            var sidebandFile = GetSidebandFile(process);

            paths = null;
            if (!FileUtilities.FileExistsNoFollow(sidebandFile))
            {
                return(failed(SidebandIntegrityCheckFailReason.FileNotFound));
            }

            using (var reader = new SidebandReader(sidebandFile))
            {
                if (!reader.ReadHeader(ignoreChecksum: false))
                {
                    return(failed(SidebandIntegrityCheckFailReason.ChecksumMismatch));
                }

                var metadata = reader.ReadMetadata();
                var expected = PipExecutor.CreateSidebandMetadata(Scheduler, process);
                if (!metadata.Equals(expected))
                {
                    return(failed(SidebandIntegrityCheckFailReason.MetadataMismatch, $"Expected: {expected}.  Actual: {metadata}"));
                }

                paths = reader.ReadRecordedPaths().Select(p => AbsolutePath.Create(Context.PathTable, p)).ToHashSet();
                return(true);
            }

            bool failed(SidebandIntegrityCheckFailReason reason, string details = "")
            {
                Logger.Log.SidebandIntegrityCheckForProcessFailed(LoggingContext, process.FormattedSemiStableHash, sidebandFile, reason.ToString(), details);
                return(false);
            }
        }