Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine whether to change Unix behavior when getting time from a non-existent file #14581

Closed
stephentoub opened this issue May 13, 2015 · 3 comments
Assignees
Labels
area-System.IO os-linux Linux OS (any supported distro)
Milestone

Comments

@stephentoub
Copy link
Member

On Windows, for back-compat reasons, getting CreationTime (and maybe last access/write time, too) from a non-existent file via FileInfo returns the equivalent of DateTime.FromFileTime(0), rather than throwing an exception. On Unix, we do what's arguably the more expected behavior and throw. We should determine whether we want to change the Unix implementation to match what's there on Windows.

@ianhays
Copy link
Contributor

ianhays commented Jul 17, 2015

I'd agree that the two implementations should function the same if at all possible. Now whether that means make them both throw or both return DateTime.FromFileTime(0), I'm not sure.

If keeping the Windows implementation as it currently stands is a necessity, then I vote we modify the Unix implementation to follow suit. If not, I think they should both throw.

Same for dotnet/corefx#2369 for Directory/DirectoryInfo

@ianhays ianhays self-assigned this Jul 17, 2015
@ianhays
Copy link
Contributor

ianhays commented Aug 11, 2015

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 ianhays closed this as completed Aug 11, 2015
rajansingh10 referenced this issue in rajansingh10/corefx Aug 12, 2015
Design review feedback brought about the closed issues #2537, #2403, #2402, #2369, #1728. This Commit cleaned up the tests around those decisions and removed OuterLoop from the GetSetTimes tests.
rajansingh10 referenced this issue in rajansingh10/corefx Aug 17, 2015
Design review feedback brought about the closed issues #2537, #2403, #2402, #2369, #1728. This Commit cleaned up the tests around those decisions and removed OuterLoop from the GetSetTimes tests.
rajansingh10 referenced this issue in rajansingh10/corefx Aug 20, 2015
Design review feedback brought about the closed issues #2537, #2403, #2402, #2369, #1728. This Commit cleaned up the tests around those decisions and removed OuterLoop from the GetSetTimes tests.
rajansingh10 referenced this issue in rajansingh10/corefx Aug 20, 2015
Design review feedback brought about the closed issues #2537, #2403, #2402, #2369, #1728. This Commit cleaned up the tests around those decisions and removed OuterLoop from the GetSetTimes tests.
rajansingh10 referenced this issue in rajansingh10/corefx Oct 16, 2015
Design review feedback brought about the closed issues #2537, #2403, #2402, #2369, #1728. This Commit cleaned up the tests around those decisions and removed OuterLoop from the GetSetTimes tests.
rajansingh10 referenced this issue in rajansingh10/corefx Oct 18, 2015
Design review feedback brought about the closed issues #2537, #2403, #2402, #2369, #1728. This Commit cleaned up the tests around those decisions and removed OuterLoop from the GetSetTimes tests.
@polarapfel
Copy link

@ianhays

I've run into issues with how FileInfo and FileSystemInfo deal with non-existent files and FileInfo instances representing them across Windows and Linux.

Consider this:

try 
{
  var doesNotExist = new FileInfo(fullPathToFileThatDoesNotExist);
  // e.g. /pathThatExists/pathThatDoesNotExist/FileThatDoesNotExist
  if (configFileInfo.Length == 0) { return false; }
  else { return true; }
}
catch (FileNotFoundException)
{
// This is thrown on Windows.
return false;
}
catch (DirectoryNotFoundException)
{
// This is thrown on Linux.
return false;
}

The same condition exists on both platforms, the same API is called, yet I get two different exception types being thrown.

Can this be fixed and in both cases the same exception is thrown?

How about throwing DirectoryNotFoundException when a partial path in the full path to the file that doesn't exist already is not present in the file system.

If the path leading up to the file not existing is present in the file system, throw a FileNotFoundException.

Good idea?

thanks,

Tobias

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 1.0.0-rtm milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.IO os-linux Linux OS (any supported distro)
Projects
None yet
Development

No branches or pull requests

4 participants