// Write "closed" entries to the archive. private void Flush() { ExceptionContext.Assert(!Disposed); ExceptionContext.AssertValue(_closed); ExceptionContext.AssertValue(_archive); while (_closed.Count > 0) { string path = null; var kvp = _closed.Dequeue(); using (var src = kvp.Value) { var fs = src as FileStream; if (fs != null) { path = fs.Name; } var ae = _archive.CreateEntry(kvp.Key); using (var dst = ae.Open()) { src.Position = 0; src.CopyTo(dst); } } if (!string.IsNullOrEmpty(path)) { File.Delete(path); } } }
/// <summary> /// Commit the writing of the repository. This signals successful completion of the write. /// </summary> public void Commit() { ExceptionContext.Check(!Disposed); ExceptionContext.AssertValue(_closed); DisposeAllEntries(); Flush(); Dispose(true); }
// The entry is being disposed. Note that this isn't supposed to throw, so we simply queue // the stream so it can be written to the archive when it IS legal to throw. protected override void OnDispose(Entry ent) { ExceptionContext.AssertValue(ent); RemoveEntry(ent); if (_closed != null) { _closed.Enqueue(new KeyValuePair <string, Stream>(ent.Path, ent.Stream)); } else { ent.Stream.CloseEx(); } }
protected override void OnDispose(Entry ent) { ExceptionContext.AssertValue(ent); RemoveEntry(ent); ent.Stream.CloseEx(); }