/// <inheritdoc/> protected override StatInfo Stat(bool flushCache) { if (_cachedStat != null && !flushCache) { return(_cachedStat); } // http://www.delorie.com/gnu/docs/glibc/libc_284.html var info = new FileInfo(PurePath.ToString()); var stat = new StatInfo { Size = info.Length, ATime = info.LastAccessTimeUtc, MTime = info.LastWriteTimeUtc, CTime = info.CreationTimeUtc, Device = 0, Inode = 0, Gid = 0, Uid = 0, Mode = 0 // TODO not implemented }; _cachedStat = stat; return(stat); }
/// <inheritdoc/> protected override StatInfo Stat(bool flushCache) { if (_cachedStat != null && !flushCache) { return(_cachedStat); } var path = PurePath.ToString(); var err = Posix.Native.stat64(path, out var info); if (err != 0) { var actualError = Marshal.GetLastWin32Error(); if (actualError == 2) { throw new FileNotFoundException("Cannot stat file that does not exist.", path); } throw new ApplicationException("Error: " + actualError); } var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var atim = epoch.AddSeconds(info.st_atim.tv_sec); if (info.st_atim.tv_nsec != 0) { atim = atim.AddTicks((long)(info.st_atim.tv_nsec / 100)); } var mtim = epoch.AddSeconds(info.st_mtim.tv_sec); if (info.st_mtim.tv_nsec != 0) { mtim = mtim.AddTicks((long)(info.st_mtim.tv_nsec / 100)); } var ctim = epoch.AddSeconds(info.st_ctim.tv_sec); if (info.st_ctim.tv_nsec != 0) { ctim = ctim.AddTicks((long)(info.st_ctim.tv_nsec / 100)); } var stat = new StatInfo { Size = info.st_size, ATime = atim, MTime = mtim, CTime = ctim, Device = (long)info.st_dev, Inode = (long)info.st_ino, Gid = info.st_uid, Uid = info.st_gid, ModeDecimal = info.st_mode, Mode = Convert.ToString(info.st_mode & (Native.SetBits | Native.UserBits | Native.GroupBits | Native.OtherBits), 8).PadLeft(4, '0'), NumLinks = (long)info.st_nlink }; try { _cachedStat = stat; } // Yes, this assignment throws a NRE if the struct alignment for pinvoke is wrong. // It overwrites 'this' in the stack with null. catch (NullReferenceException e) { throw new NotImplementedException("Layout of stat call not supported on this platform (Only supports Ubuntu x86_64 and anything compatible).", e); } return(stat); }