[corlib] Remove the File.Exists check before opening the file.
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 15 May 2017 23:17:23 +0000 (16:17 -0700)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 15 May 2017 23:17:23 +0000 (16:17 -0700)
It's both racy and not necessary.

Beyond that, it will produce the wrong exception if opening the file fails for a different reason that it's missing.

This is an issue in case of bad permissions or symlink loops.

mcs/class/corlib/System.IO/FileStream.cs

index 664d9305745369610b87f6ce3d9a44050db45507..f6b752d1784fdb631a7f8439de3426608c39c963 100644 (file)
@@ -224,14 +224,6 @@ namespace System.IO
                                }
                        }
 
-                       if (access == FileAccess.Read && mode != FileMode.Create && mode != FileMode.OpenOrCreate &&
-                                       mode != FileMode.CreateNew && !File.Exists (path)) {
-                               // don't leak the path information for isolated storage
-                               string msg = Locale.GetText ("Could not find file \"{0}\".");
-                               string fname = GetSecureFileName (path);
-                               throw new FileNotFoundException (String.Format (msg, fname), fname);
-                       }
-
                        // IsolatedStorage needs to keep the Name property to the default "[Unknown]"
                        if (!anonymous)
                                this.name = path;