Exemple #1
0
        private void InvalidateSidebandFile(string sidebandFile, SidebandIntegrityCheckFailReason kind)
        {
            XAssert.FileExists(sidebandFile, "Sideband file for pipA not found.");
            switch (kind)
            {
            case SidebandIntegrityCheckFailReason.FileNotFound:
                AssertDeleteFile(sidebandFile, "Could not delete sideband file for pipA.");
                break;

            case SidebandIntegrityCheckFailReason.ChecksumMismatch:
                File.WriteAllText(path: sidebandFile, contents: "bogus sideband file");
                break;

            case SidebandIntegrityCheckFailReason.MetadataMismatch:
                SidebandMetadata alteredMetadata;
                // read the header and the metadata from the original
                using (var reader = new SidebandReader(sidebandFile))
                {
                    XAssert.IsTrue(reader.ReadHeader(ignoreChecksum: false));
                    var originalMetadata = reader.ReadMetadata();
                    alteredMetadata = new SidebandMetadata(originalMetadata.PipSemiStableHash + 1, originalMetadata.StaticPipFingerprint);
                }
                // overwrite the original with a different metadata file where PiPSemiStableHash is different than in the original
                using (var writer = new SidebandWriter(alteredMetadata, sidebandFile, null))
                {
                    writer.EnsureHeaderWritten();
                }
                break;

            default:
                XAssert.Fail($"Unknown kind: {kind}");
                break;
            }
        }
 private bool TryReadSidebandFile(string filename, out SidebandMetadata metadata, out IEnumerable <string> paths)
 {
     try
     {
         // We ignore the checksum because even when the sideband file is compromised,
         // it is possible to call <see cref="ReadRecordedPaths"/> which will then try to recover
         // as many recorded paths as possible.
         (paths, metadata) = SidebandReader.ReadSidebandFile(filename, ignoreChecksum: true);
         return(true);
     }
     catch (Exception e) when(e is BuildXLException || e is IOException || e is OperationCanceledException)
     {
         Processes.Tracing.Logger.Log.CannotReadSidebandFileWarning(LoggingContext, filename, e.Message);
         metadata = null;
         paths    = null;
         return(false);
     }
 }
Exemple #3
0
 private SidebandWriter CreateWriter(string sidebandFile = null, IReadOnlyList <string> rootDirs = null, SidebandMetadata metadata = null)
 {
     sidebandFile = sidebandFile ?? Path.Combine(TemporaryDirectory, $"{s_logDirectoryCounter++}", "log");
     Directory.CreateDirectory(Path.GetDirectoryName(sidebandFile));
     return(new SidebandWriter(
                metadata: metadata ?? DefaultSidebandMetadata,
                sidebandLogFile: sidebandFile,
                rootDirectories: rootDirs));
 }