internal WriteFileContext(string filename, string templateFilename) { string directoryname = UrlPath.GetDirectoryOrRootName(filename); _templateFilename = templateFilename; _tempFiles = new IO.Internal.TempFileCollection(directoryname); try { TempNewFilename = _tempFiles.AddExtension("newcfg"); } catch { ((IDisposable)_tempFiles).Dispose(); _tempFiles = null; throw; } }
// Cleanup the WriteFileContext object based on either success // or failure // // Note: The current algorithm guarantess // 1) The file we are saving to will always be present // on the file system (ie. there will be no window // during saving in which there won't be a file there) // 2) It will always be available for reading from a // client and it will be complete and accurate. // // ... This means that writing is a bit more complicated, and may // have to be retried (because of reading lock), but I don't see // anyway to get around this given 1 and 2. internal void Complete(string filename, bool success) { try { if (!success) { return; } if (File.Exists(filename)) { // Test that we can write to the file ValidateWriteAccess(filename); // Copy Attributes from original DuplicateFileAttributes(filename, TempNewFilename); } else { if (_templateFilename != null) { // Copy Acl from template file DuplicateTemplateAttributes(_templateFilename, TempNewFilename); } } ReplaceFile(TempNewFilename, filename); // Don't delete, since we just moved it. _tempFiles.KeepFiles = true; } finally { ((IDisposable)_tempFiles).Dispose(); _tempFiles = null; } }