/// <summary> /// Create a managed replica of the native stat structure. /// </summary> /// <param name="css">The common stat structure from which we copy.</param> /// <returns>A managed common stat class instance.</returns> private static CommonStat CopyStatStruct(NativeMethods.CommonStatStruct css) { CommonStat cs = new CommonStat(); cs.Inode = css.Inode; cs.Mode = css.Mode; cs.UserId = css.UserId; cs.GroupId = css.GroupId; cs.HardlinkCount = css.HardlinkCount; cs.Size = css.Size; cs.AccessTime = DateTime.UnixEpoch.AddSeconds(css.AccessTime).ToLocalTime(); cs.ModifiedTime = DateTime.UnixEpoch.AddSeconds(css.ModifiedTime).ToLocalTime(); cs.StatusChangeTime = DateTime.UnixEpoch.AddSeconds(css.StatusChangeTime).ToLocalTime(); cs.BlockSize = css.BlockSize; cs.DeviceId = css.DeviceId; cs.NumberOfBlocks = css.NumberOfBlocks; if (css.IsDirectory == 1) { cs.ItemType = ItemType.Directory; } else if (css.IsFile == 1) { cs.ItemType = ItemType.File; } else if (css.IsSymbolicLink == 1) { cs.ItemType = ItemType.SymbolicLink; } else if (css.IsBlockDevice == 1) { cs.ItemType = ItemType.BlockDevice; } else if (css.IsCharacterDevice == 1) { cs.ItemType = ItemType.CharacterDevice; } else if (css.IsNamedPipe == 1) { cs.ItemType = ItemType.NamedPipe; } else { cs.ItemType = ItemType.Socket; } cs.IsSetUid = css.IsSetUid == 1; cs.IsSetGid = css.IsSetGid == 1; cs.IsSticky = css.IsSticky == 1; return(cs); }
/// <summary> /// Create a managed replica of the native stat structure. /// </summary> /// <param name="css">The common stat structure from which we copy.</param> /// <returns>A managed common stat class instance.</returns> private static CommonStat CopyStatStruct(NativeMethods.CommonStatStruct css) { CommonStat cs = new CommonStat(); cs.Inode = css.Inode; cs.Mode = css.Mode; cs.UserId = css.UserId; cs.GroupId = css.GroupId; cs.HardlinkCount = css.HardlinkCount; cs.Size = css.Size; // These can sometime throw if we get too large a number back (seen on Raspbian). // As a fallback, set the time to UnixEpoch. try { cs.AccessTime = DateTime.UnixEpoch.AddSeconds(css.AccessTime).ToLocalTime(); } catch { cs.AccessTime = DateTime.UnixEpoch.ToLocalTime(); } try { cs.ModifiedTime = DateTime.UnixEpoch.AddSeconds(css.ModifiedTime).ToLocalTime(); } catch { cs.ModifiedTime = DateTime.UnixEpoch.ToLocalTime(); } try { cs.StatusChangeTime = DateTime.UnixEpoch.AddSeconds(css.StatusChangeTime).ToLocalTime(); } catch { cs.StatusChangeTime = DateTime.UnixEpoch.ToLocalTime(); } cs.BlockSize = css.BlockSize; cs.DeviceId = css.DeviceId; cs.NumberOfBlocks = css.NumberOfBlocks; if (css.IsDirectory == 1) { cs.ItemType = ItemType.Directory; } else if (css.IsFile == 1) { cs.ItemType = ItemType.File; } else if (css.IsSymbolicLink == 1) { cs.ItemType = ItemType.SymbolicLink; } else if (css.IsBlockDevice == 1) { cs.ItemType = ItemType.BlockDevice; } else if (css.IsCharacterDevice == 1) { cs.ItemType = ItemType.CharacterDevice; } else if (css.IsNamedPipe == 1) { cs.ItemType = ItemType.NamedPipe; } else { cs.ItemType = ItemType.Socket; } cs.IsSetUid = css.IsSetUid == 1; cs.IsSetGid = css.IsSetGid == 1; cs.IsSticky = css.IsSticky == 1; return(cs); }