Skip to content

Commit

Permalink
Handle unknown user/group IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
fubar-coder committed Jun 3, 2019
1 parent fa47735 commit f8d9779
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/FubarDev.FtpServer.FileSystem.Unix/UnixFileSystemEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// </copyright>

using System;
using System.Globalization;

using JetBrains.Annotations;

Expand All @@ -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);
}

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

/// <inheritdoc />
public string Owner => _info.OwnerUser.UserName;
public string Owner { get; }

/// <inheritdoc />
public string Group => _info.OwnerGroup.GroupName;
public string Group { get; }

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

/// <inheritdoc />
public long NumberOfLinks => _info.LinkCount;

private static string GetNameOrId(Func<string> getName, Func<long> getId)
{
try
{
return getName();
}
catch
{
return getId().ToString(CultureInfo.InvariantCulture);
}
}
}
}

0 comments on commit f8d9779

Please sign in to comment.