From f8d97791fbad8995154bc294b05b18f4a45f83f4 Mon Sep 17 00:00:00 2001 From: Mark Junker Date: Mon, 3 Jun 2019 23:09:46 +0200 Subject: [PATCH] Handle unknown user/group IDs --- .../UnixFileSystemEntry.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/FubarDev.FtpServer.FileSystem.Unix/UnixFileSystemEntry.cs b/src/FubarDev.FtpServer.FileSystem.Unix/UnixFileSystemEntry.cs index c7ed99a6..af8808a2 100644 --- a/src/FubarDev.FtpServer.FileSystem.Unix/UnixFileSystemEntry.cs +++ b/src/FubarDev.FtpServer.FileSystem.Unix/UnixFileSystemEntry.cs @@ -3,6 +3,7 @@ // using System; +using System.Globalization; using JetBrains.Annotations; @@ -20,6 +21,8 @@ protected UnixFileSystemEntry( { GenericInfo = _info = info; Permissions = new UnixPermissions(info); + Owner = GetNameOrId(() => info.OwnerUser.UserName, () => info.OwnerUserId); + Group = GetNameOrId(() => info.OwnerGroup.GroupName, () => info.OwnerGroupId); } /// @@ -29,10 +32,10 @@ protected UnixFileSystemEntry( public UnixFileSystemInfo GenericInfo { get; } /// - public string Owner => _info.OwnerUser.UserName; + public string Owner { get; } /// - public string Group => _info.OwnerGroup.GroupName; + public string Group { get; } /// public string Name => _info.Name; @@ -48,5 +51,17 @@ protected UnixFileSystemEntry( /// public long NumberOfLinks => _info.LinkCount; + + private static string GetNameOrId(Func getName, Func getId) + { + try + { + return getName(); + } + catch + { + return getId().ToString(CultureInfo.InvariantCulture); + } + } } }