[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)
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

index 22de37d7cf1acc9a2aee5624573bba4e69c2067a..0585986e83d623a64cfac6c625a2fa050c8486e7 100644 (file)
@@ -462,6 +462,10 @@ namespace System.IO {
                                        if (ex.hresult != MonoIO.FileAlreadyExistsHResult || count ++ > 65536)
                                                throw;
                                }
+                               catch (UnauthorizedAccessException ex) {
+                                       if (count ++ > 65536)
+                                               throw new IOException (ex.Message, ex);
+                               }
                        } while (f == null);
                        
                        f.Close();