/// <summary>Returns the file stat for a file descriptor.</summary> /// <param name="fd">file descriptor.</param> /// <returns>the file descriptor file stat.</returns> /// <exception cref="System.IO.IOException">thrown if there was an IO error while obtaining the file stat. /// </exception> public static NativeIO.POSIX.Stat GetFstat(FileDescriptor fd) { NativeIO.POSIX.Stat stat = null; if (!Shell.Windows) { stat = Fstat(fd); stat.owner = GetName(NativeIO.POSIX.IdCache.User, stat.ownerId); stat.group = GetName(NativeIO.POSIX.IdCache.Group, stat.groupId); } else { try { stat = Fstat(fd); } catch (NativeIOException nioe) { if (nioe.GetErrorCode() == 6) { throw new NativeIOException("The handle is invalid.", Errno.Ebadf); } else { Log.Warn(string.Format("NativeIO.getFstat error (%d): %s", nioe.GetErrorCode(), nioe .Message)); throw new NativeIOException("Unknown error", Errno.Unknown); } } } return(stat); }
/// <exception cref="System.Exception"/> public virtual void TestFstat() { FileOutputStream fos = new FileOutputStream(new FilePath(TestDir, "testfstat")); NativeIO.POSIX.Stat stat = NativeIO.POSIX.GetFstat(fos.GetFD()); fos.Close(); Log.Info("Stat: " + stat.ToString()); string owner = stat.GetOwner(); string expectedOwner = Runtime.GetProperty("user.name"); if (Path.Windows) { UserGroupInformation ugi = UserGroupInformation.CreateRemoteUser(expectedOwner); string adminsGroupString = "Administrators"; if (Arrays.AsList(ugi.GetGroupNames()).Contains(adminsGroupString)) { expectedOwner = adminsGroupString; } } Assert.Equal(expectedOwner, owner); NUnit.Framework.Assert.IsNotNull(stat.GetGroup()); Assert.True(!stat.GetGroup().IsEmpty()); Assert.Equal("Stat mode field should indicate a regular file", NativeIO.POSIX.Stat.SIfreg, stat.GetMode() & NativeIO.POSIX.Stat.SIfmt); }
/// <exception cref="System.Exception"/> public virtual void TestFstatClosedFd() { FileOutputStream fos = new FileOutputStream(new FilePath(TestDir, "testfstat2")); fos.Close(); try { NativeIO.POSIX.Stat stat = NativeIO.POSIX.GetFstat(fos.GetFD()); } catch (NativeIOException nioe) { Log.Info("Got expected exception", nioe); Assert.Equal(Errno.Ebadf, nioe.GetErrno()); } }
public override void Run() { long et = Time.Now() + 5000; while (Time.Now() < et) { try { NativeIO.POSIX.Stat stat = NativeIO.POSIX.GetFstat(fos.GetFD()); Assert.Equal(Runtime.GetProperty("user.name"), stat.GetOwner() ); NUnit.Framework.Assert.IsNotNull(stat.GetGroup()); Assert.True(!stat.GetGroup().IsEmpty()); Assert.Equal("Stat mode field should indicate a regular file", NativeIO.POSIX.Stat.SIfreg, stat.GetMode() & NativeIO.POSIX.Stat.SIfmt); } catch (Exception t) { thrown.Set(t); } } }