}
public DateTime LastAccessTime {
- get {AssertValid (); return Native.NativeConvert.ToDateTime (stat.st_atime);}
+ get {AssertValid (); return Native.NativeConvert.ToDateTime (stat.st_atime, stat.st_atime_nsec);}
}
public DateTime LastAccessTimeUtc {
}
public DateTime LastWriteTime {
- get {AssertValid (); return Native.NativeConvert.ToDateTime (stat.st_mtime);}
+ get {AssertValid (); return Native.NativeConvert.ToDateTime (stat.st_mtime, stat.st_mtime_nsec);}
}
public DateTime LastWriteTimeUtc {
}
public DateTime LastStatusChangeTime {
- get {AssertValid (); return Native.NativeConvert.ToDateTime (stat.st_ctime);}
+ get {AssertValid (); return Native.NativeConvert.ToDateTime (stat.st_ctime, stat.st_ctime_nsec);}
}
public DateTime LastStatusChangeTimeUtc {
{
int r = Native.Syscall.link (FullName, path);
UnixMarshal.ThrowExceptionForLastErrorIf (r);
- return Create (path);
+ return GetFileSystemEntry (path);
}
public UnixSymbolicLinkInfo CreateSymbolicLink (string path)
return stat;
}
- internal static UnixFileSystemInfo Create (string path)
+ public static UnixFileSystemInfo GetFileSystemEntry (string path)
+ {
+ UnixFileSystemInfo info;
+ if (TryGetFileSystemEntry (path, out info))
+ return info;
+
+ UnixMarshal.ThrowExceptionForLastError ();
+
+ // Throw DirectoryNotFoundException because lstat(2) probably failed
+ // because of ENOTDIR (e.g. "/path/to/file/wtf"), so
+ // DirectoryNotFoundException is what would have been thrown anyway.
+ throw new DirectoryNotFoundException ("UnixMarshal.ThrowExceptionForLastError didn't throw?!");
+ }
+
+ public static bool TryGetFileSystemEntry (string path, out UnixFileSystemInfo entry)
{
Native.Stat stat;
int r = Native.Syscall.lstat (path, out stat);
- if (r == -1 && Native.Stdlib.GetLastError() == Native.Errno.ENOENT) {
- return new UnixFileInfo (path);
+ if (r == -1) {
+ if (Native.Stdlib.GetLastError() == Native.Errno.ENOENT) {
+ entry = new UnixFileInfo (path);
+ return true;
+ }
+ entry = null;
+ return false;
}
- UnixMarshal.ThrowExceptionForLastErrorIf (r);
if (IsFileType (stat.st_mode, Native.FilePermissions.S_IFDIR))
- return new UnixDirectoryInfo (path, stat);
+ entry = new UnixDirectoryInfo (path, stat);
else if (IsFileType (stat.st_mode, Native.FilePermissions.S_IFLNK))
- return new UnixSymbolicLinkInfo (path, stat);
- return new UnixFileInfo (path, stat);
+ entry = new UnixSymbolicLinkInfo (path, stat);
+ else
+ entry = new UnixFileInfo (path, stat);
+
+ return true;
}
}
}