/// <summary> /// Updates the commit context and writes it to a file, signifying that all /// the file systems have been provisionally committed. /// </summary> /// <returns>The <see cref="Result"/> of the operation.</returns> public Result CommitProvisionallyDone() { IFile contextFile = null; try { Result rc = _fileSystem.OpenFile(out contextFile, CommitContextFileName, OpenMode.ReadWrite); if (rc.IsFailure()) { return(rc); } _context.State = CommitState.ProvisionallyCommitted; rc = contextFile.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOption.None); if (rc.IsFailure()) { return(rc); } rc = contextFile.Flush(); if (rc.IsFailure()) { return(rc); } } finally { contextFile?.Dispose(); } return(_fileSystem.Commit()); }
/// <summary> /// Creates and writes the initial commit context to a file. /// </summary> /// <param name="commitCount">The counter.</param> /// <param name="fileSystemCount">The number of file systems being committed.</param> /// <returns>The <see cref="Result"/> of the operation.</returns> public Result Create(long commitCount, int fileSystemCount) { IFile contextFile = null; try { // Open context file and create if it doesn't exist Result rc = _fileSystem.OpenFile(out contextFile, CommitContextFileName, OpenMode.Read); if (rc.IsFailure()) { if (!ResultFs.PathNotFound.Includes(rc)) { return(rc); } rc = _fileSystem.CreateFile(CommitContextFileName, CommitContextFileSize, CreateFileOptions.None); if (rc.IsFailure()) { return(rc); } rc = _fileSystem.OpenFile(out contextFile, CommitContextFileName, OpenMode.Read); if (rc.IsFailure()) { return(rc); } } } finally { contextFile?.Dispose(); } try { Result rc = _fileSystem.OpenFile(out contextFile, CommitContextFileName, OpenMode.ReadWrite); if (rc.IsFailure()) { return(rc); } _context.Version = CurrentCommitContextVersion; _context.State = CommitState.NotCommitted; _context.FileSystemCount = fileSystemCount; _context.Counter = commitCount; // Write the initial context to the file rc = contextFile.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOption.None); if (rc.IsFailure()) { return(rc); } rc = contextFile.Flush(); if (rc.IsFailure()) { return(rc); } } finally { contextFile?.Dispose(); } return(_fileSystem.Commit()); }