runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Directory AccessTime, WriteTime, and CreationTime for nonexistent directories inconsistent

Open ianhays opened this issue 11 years ago • 3 comments

Labeld in code as "//See VSWhidbey # 92050"

On Windows, Directory.GetAccessTime, Directory.GetWriteTime, and Directory.GetCreationTime (as well as their DirectoryInfo clones) will return default values when queried with a path to a nonexistent directory.

On Unix, running those same methods for AccessTime and WriteTime throws a "FileNotFoundException".

Is this behavioral difference desired?

Example:

Assert.Equal(DateTime.FromFileTime(0).Ticks, Directory.GetLastAccessTime("doesntexist").Ticks); //true on Windows, throws on Ubuntu
Assert.Equal(DateTime.FromFileTime(0).Ticks, Directory.GetLastWriteTime("doesntexist").Ticks); //same as above

ianhays avatar Jul 15 '15 16:07 ianhays

This is the same as https://github.com/dotnet/corefx/issues/1728, right?

stephentoub avatar Jul 15 '15 17:07 stephentoub

Essentially yes, but with Directory/DirectoryInfo instead of File/FileInfo.

ianhays avatar Jul 15 '15 17:07 ianhays

Design review feedback leaned towards allowing Unix to have a different behavior than Windows because of the Windows-specific notions of FromFileTime, though it wasn't entirely conclusive. Changing the Windows behavior is not what we want to do because of the breaking change it would cause, so the best option is different behaviors on different systems.

Returning the windows 0 time on a Unix machine wouldn't make any sense and returning the Unix 0 time would still be inconsistent with the Windows 0 time, so the better alternative of throwing an exception is chosen.

ianhays avatar Aug 11 '15 20:08 ianhays