public bool AppendLine(string data) { Contract.Ensures(data != null || IsFrozen); if (m_exception != null) { return(true); } Contract.Assert(!IsFrozen); if (data == null) { ReleaseTextWriter(); IsFrozen = true; } else { m_observer?.Invoke(data); m_length += data.Length + Environment.NewLine.Length; if (m_textWriter != null) { HandleRecoverableIOException(() => m_textWriter.WriteLine(data)); } else { m_stringBuilder.AppendLine(data); Contract.Assert(m_stringBuilder.Length == m_length); if (m_length > m_maxMemoryLength) { m_fileName = m_fileStorage.GetFileName(m_file); HandleRecoverableIOException( () => { FileUtilities.CreateDirectory(Path.GetDirectoryName(m_fileName)); // Note that we use CreateReplacementFile since the target may be a read-only hardlink (e.g. in the build cache). FileStream stream = FileUtilities.CreateReplacementFile( m_fileName, FileShare.Read | FileShare.Delete, openAsync: false); m_textWriter = new StreamWriter(stream, Encoding); m_textWriter.Write(m_stringBuilder.ToString()); ReleaseStringBuilder(); }); } } } return(true); }
private async Task InternalSaveAsync() { string fileName = m_fileStorage.GetFileName(m_file); FileUtilities.CreateDirectory(Path.GetDirectoryName(fileName)); await FileUtilities.WriteAllTextAsync(fileName, m_value, m_encoding); string existingFileName = Interlocked.CompareExchange(ref m_fileName, fileName, comparand: null); Contract.Assume(existingFileName == null, "Sandboxed process output should only be saved once (via InternalSaveAsync)"); m_saveTask = Unit.VoidTask; }
/// <summary> /// Creates an instance of <see cref="SandboxedProcessStandardFiles"/> from <see cref="ISandboxedProcessFileStorage"/>. /// </summary> public static SandboxedProcessStandardFiles From(ISandboxedProcessFileStorage fileStorage) => new SandboxedProcessStandardFiles( fileStorage.GetFileName(SandboxedProcessFile.StandardOutput), fileStorage.GetFileName(SandboxedProcessFile.StandardError));