{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/docs/issues/4343","repository_url":"https://api.github.com/repos/dotnet/docs","labels_url":"https://api.github.com/repos/dotnet/docs/issues/4343/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/docs/issues/4343/comments","events_url":"https://api.github.com/repos/dotnet/docs/issues/4343/events","html_url":"https://github.com/dotnet/docs/issues/4343","id":295651671,"number":4343,"title":"Documentation for FileInfo.Exists and File.Exists is misleading","user":{"login":"jhudsoncedaron","id":17086870,"avatar_url":"https://avatars0.githubusercontent.com/u/17086870?v=4","gravatar_id":"","url":"https://api.github.com/users/jhudsoncedaron","html_url":"https://github.com/jhudsoncedaron","followers_url":"https://api.github.com/users/jhudsoncedaron/followers","following_url":"https://api.github.com/users/jhudsoncedaron/following{/other_user}","gists_url":"https://api.github.com/users/jhudsoncedaron/gists{/gist_id}","starred_url":"https://api.github.com/users/jhudsoncedaron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhudsoncedaron/subscriptions","organizations_url":"https://api.github.com/users/jhudsoncedaron/orgs","repos_url":"https://api.github.com/users/jhudsoncedaron/repos","events_url":"https://api.github.com/users/jhudsoncedaron/events{/privacy}","received_events_url":"https://api.github.com/users/jhudsoncedaron/received_events","type":"User","site_admin":false},"labels":[{"id":659692058,"url":"https://api.github.com/repos/dotnet/docs/labels/Area%20-%20.NET%20Guide","name":"Area - .NET Guide","color":"3d5c8e","default":false},{"id":340926325,"url":"https://api.github.com/repos/dotnet/docs/labels/Area%20-%20API%20Reference","name":"Area - API Reference","color":"3d5c8e","default":false},{"id":325357852,"url":"https://api.github.com/repos/dotnet/docs/labels/P2","name":"P2","color":"0e8a16","default":false},{"id":213467663,"url":"https://api.github.com/repos/dotnet/docs/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":298147526,"url":"https://api.github.com/repos/dotnet/docs/labels/up-for-grabs","name":"up-for-grabs","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/dotnet/docs/milestones/31","html_url":"https://github.com/dotnet/docs/milestone/31","labels_url":"https://api.github.com/repos/dotnet/docs/milestones/31/labels","id":2941332,"number":31,"title":"2018 - Quarter 1","description":"","creator":{"login":"mairaw","id":12971179,"avatar_url":"https://avatars2.githubusercontent.com/u/12971179?v=4","gravatar_id":"","url":"https://api.github.com/users/mairaw","html_url":"https://github.com/mairaw","followers_url":"https://api.github.com/users/mairaw/followers","following_url":"https://api.github.com/users/mairaw/following{/other_user}","gists_url":"https://api.github.com/users/mairaw/gists{/gist_id}","starred_url":"https://api.github.com/users/mairaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mairaw/subscriptions","organizations_url":"https://api.github.com/users/mairaw/orgs","repos_url":"https://api.github.com/users/mairaw/repos","events_url":"https://api.github.com/users/mairaw/events{/privacy}","received_events_url":"https://api.github.com/users/mairaw/received_events","type":"User","site_admin":false},"open_issues":45,"closed_issues":0,"state":"open","created_at":"2017-11-27T21:23:49Z","updated_at":"2018-02-12T21:21:32Z","due_on":"2018-03-31T07:00:00Z","closed_at":null},"comments":2,"created_at":"2018-02-08T20:18:42Z","updated_at":"2018-02-12T21:23:23Z","closed_at":null,"author_association":"NONE","body":"Documentation for FileInfo.Exists and File.Exists is misleading\r\n\r\nFile.Exists \"returns\" currently reads:\r\n\r\ntrue if the caller has the required permissions and path contains the name of an existing file; otherwise, false. This method also returns false if path is null, an invalid path, or a zero-length string. If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.\r\n\r\nShould read:\r\n\r\ntrue if the caller has the required permissions and path contains the name of an existing file; otherwise, false. This method also returns false on an invalid filename or if any error prevents determining if the file exists or not.\r\n\r\nFileSystemInfo.Exists \"returns\" currently reads:\r\n\r\ntrue if the file or directory exists; otherwise, false.\r\n\r\nShould read:\r\n\r\ntrue if the file or directory is known to exist; otherwise, false. This method returns false if an error prevented determining if the file exists or not. If FileSystemInfo.Exists returns false, call FileSystemInfo.tLastWriteTimeUTC to throw the exception for the error. If LastWriteTimeUTC returns at all, the file or directory is known to not exist.\r\n\r\nRemakrs on FileSystemInfo.Exists should contain this blob:\r\n\r\nFileSystemInfo reports on existence based on a snapshot of the file in question that may be invalid by the time FileSystemInfo.Exists() returns. Therefore, the following code can still throw FileNotFoundException: var fileinfo = new FileInfo(pathstring); if (fileinfo.Exists()) using (var f = new FileStream(fileinfo.FullName, FileMode.Open) { /* ... */ } else {var ignoredvalue = fileInfo.LastWriteTimeUTC; }\r\n\r\nGeneral Commentary (why these specific changes):\r\n\r\nNot checking if the result of FileInfo.Exists is trustworthy is almost always a bug, and is always a bug in batch processing (and therefore all library modules). File.Exists() has no use for the reason of there being no way to check if false was a successful false or an error. Just calling fileInfo.LastWriteTimeUTC != new DateTime(1601, 1, 1, 0, 0, 0) as FileInfo.Exists won't work because that's a valid time that somebody could have set a file to. (And I don't trust that value's right on Unix anyway but I digress.)\r\n\r\nMost of the time, FileInfo isn't what you want anyway. The static file provider in MVC has some bizarre corner case bugs that would not exist had it checked for a file's existence by opening it and catching FileNotFoundException.\r\n\r\nOriginal Discussion: https://github.com/dotnet/corefx/issues/26893"},"comment":{"url":"https://api.github.com/repos/dotnet/docs/issues/comments/365066597","html_url":"https://github.com/dotnet/docs/issues/4343#issuecomment-365066597","issue_url":"https://api.github.com/repos/dotnet/docs/issues/4343","id":365066597,"user":{"login":"mairaw","id":12971179,"avatar_url":"https://avatars2.githubusercontent.com/u/12971179?v=4","gravatar_id":"","url":"https://api.github.com/users/mairaw","html_url":"https://github.com/mairaw","followers_url":"https://api.github.com/users/mairaw/followers","following_url":"https://api.github.com/users/mairaw/following{/other_user}","gists_url":"https://api.github.com/users/mairaw/gists{/gist_id}","starred_url":"https://api.github.com/users/mairaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mairaw/subscriptions","organizations_url":"https://api.github.com/users/mairaw/orgs","repos_url":"https://api.github.com/users/mairaw/repos","events_url":"https://api.github.com/users/mairaw/events{/privacy}","received_events_url":"https://api.github.com/users/mairaw/received_events","type":"User","site_admin":false},"created_at":"2018-02-12T21:23:23Z","updated_at":"2018-02-12T21:23:23Z","author_association":"CONTRIBUTOR","body":"Thanks @jhudsoncedaron and @JeremyKuhne. The way I see this, we need to update the API docs to change the description/remarks and some of the IO conceptual articles to explain the transient nature of I/O operations. The IntelliSense gets updated with the content fixes we make here on a certain cadence."}}
{"actor":{"display_login":"mairaw"}}