Skip to content

Commit f8d9779

Browse files
committed
Handle unknown user/group IDs
1 parent fa47735 commit f8d9779

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/FubarDev.FtpServer.FileSystem.Unix/UnixFileSystemEntry.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// </copyright>
44

55
using System;
6+
using System.Globalization;
67

78
using JetBrains.Annotations;
89

@@ -20,6 +21,8 @@ protected UnixFileSystemEntry(
2021
{
2122
GenericInfo = _info = info;
2223
Permissions = new UnixPermissions(info);
24+
Owner = GetNameOrId(() => info.OwnerUser.UserName, () => info.OwnerUserId);
25+
Group = GetNameOrId(() => info.OwnerGroup.GroupName, () => info.OwnerGroupId);
2326
}
2427

2528
/// <summary>
@@ -29,10 +32,10 @@ protected UnixFileSystemEntry(
2932
public UnixFileSystemInfo GenericInfo { get; }
3033

3134
/// <inheritdoc />
32-
public string Owner => _info.OwnerUser.UserName;
35+
public string Owner { get; }
3336

3437
/// <inheritdoc />
35-
public string Group => _info.OwnerGroup.GroupName;
38+
public string Group { get; }
3639

3740
/// <inheritdoc />
3841
public string Name => _info.Name;
@@ -48,5 +51,17 @@ protected UnixFileSystemEntry(
4851

4952
/// <inheritdoc />
5053
public long NumberOfLinks => _info.LinkCount;
54+
55+
private static string GetNameOrId(Func<string> getName, Func<long> getId)
56+
{
57+
try
58+
{
59+
return getName();
60+
}
61+
catch
62+
{
63+
return getId().ToString(CultureInfo.InvariantCulture);
64+
}
65+
}
5166
}
5267
}

0 commit comments

Comments
 (0)