File.Unix.cs 960 B

12345678910111213141516171819202122232425
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. namespace Internal.IO
  5. {
  6. internal static partial class File
  7. {
  8. internal static bool InternalExists(string fullPath)
  9. {
  10. Interop.Sys.FileStatus fileinfo;
  11. // First use stat, as we want to follow symlinks. If that fails, it could be because the symlink
  12. // is broken, we don't have permissions, etc., in which case fall back to using LStat to evaluate
  13. // based on the symlink itself.
  14. if (Interop.Sys.Stat(fullPath, out fileinfo) < 0 &&
  15. Interop.Sys.LStat(fullPath, out fileinfo) < 0)
  16. {
  17. return false;
  18. }
  19. return ((fileinfo.Mode & Interop.Sys.FileTypes.S_IFMT) != Interop.Sys.FileTypes.S_IFDIR);
  20. }
  21. }
  22. }