[corlib] Don't throw UnauthorizedAccessException from Path.GetTempFileName
authorJonathan Pryor <jonpryor@vt.edu>
Mon, 3 Jun 2013 20:54:11 +0000 (16:54 -0400)
committerJonathan Pryor <jonpryor@vt.edu>
Mon, 3 Jun 2013 20:57:31 +0000 (16:57 -0400)
commitb1f4d6dfccc2e64c2fff38783b267def5c811899
tree668fa8754ee62aed4831879f3bf5d0e5a41d0bca
parentc3bd60f84242c9d18d10134ecfc519a557943ef3
[corlib] Don't throw UnauthorizedAccessException from Path.GetTempFileName

The problem is sporadic mdoc test failures on Wrench/OS X:

Updating: Mono.DocTest.Widget/NestedClass/Double/Triple/Quadruple
mdoc: System.UnauthorizedAccessException: Access to the path '/var/folders/_g/y9v720_90l914yylrk7m903c0000gn/T/tmp20f71445.tmp' is denied.
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,bool,System.IO.FileOptions)
  at System.IO.Path.GetTempFileName () [0x00000] in <filename unknown>:0
  at Mono.Documentation.MdocFile.UpdateFile (System.String file, System.Action`1 creator) [0x00000] in <filename unknown>:0
  at Mono.Documentation.MDocUpdater.WriteFile (System.String filename, FileMode mode, System.Action`1 action) [0x00000] in <filename unknown>:0
  at Mono.Documentation.MDocUpdater.DoUpdateType2 (System.String message, System.Xml.XmlDocument basefile, Mono.Cecil.TypeDefinition type, System.String output, Boolean insertSince) [0x00000] in <filename unknown>:0
  at Mono.Documentation.MDocUpdater.DoUpdateType (Mono.Cecil.TypeDefinition type, System.String basepath, System.String dest) [0x00000] in <filename unknown>:0
  at Mono.Documentation.MDocUpdater.DoUpdateAssembly (Mono.Cecil.AssemblyDefinition assembly, System.Xml.XmlElement index_types, System.String source, System.String dest, System.Collections.Generic.HashSet`1 goodfiles) [0x00000] in <filename unknown>:0
  at Mono.Documentation.MDocUpdater.DoUpdateAssemblies (System.String source, System.String dest) [0x00000] in <filename unknown>:0
  at Mono.Documentation.MDocUpdater.Run (IEnumerable`1 args) [0x00000] in <filename unknown>:0
  at Mono.Documentation.MDoc.Run (System.String[] args) [0x00000] in <filename unknown>:0
  at Mono.Documentation.MDoc.Main (System.String[] args) [0x00000] in <filename unknown>:0

I'm not sure why we're getting UnauthorizedAccessException exceptions,
nor do I particularly care; Path.GetTempFileName() should not be
throwing UnauthorizedAccessException; only IOException is documented:

http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename.aspx

Update behavior to skip files that generate
UnauthorizedAccessException, and if we swallow short.MaxValue
exceptions wrap the UnauthorizedAccessException in an IOException so
that we conform to documented exceptional behavior.
mcs/class/corlib/System.IO/Path.cs