static internal void StaticWriteCompleted(string streamName, bool success, object writeContext, bool assertPermissions) {
WriteFileContext writeFileContext = (WriteFileContext) writeContext;
bool revertAssert = false;
if (assertPermissions) {
// If asked to assert permissions, we will assert allAccess on the streamName, the temporary file
// created by WriteContext, and also the directory itself. The last one is needed because
// WriteFileContext will call TempFileCollection.Dispose, which will remove a .tmp file it created.
string dir = Path.GetDirectoryName(streamName);
string[] filePaths = new string[] {streamName, writeFileContext.TempNewFilename, dir};
FileIOPermission fileIOPerm = new FileIOPermission(FileIOPermissionAccess.AllAccess,
filePaths);
fileIOPerm.Assert();
revertAssert = true;
}
try {
writeFileContext.Complete(streamName, success);
}
finally {
if (revertAssert) {
CodeAccessPermission.RevertAssert();
}
}
}