From 7f4c8cc8b92dd5aa3b5f22b43fea698e775e928f Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Sun, 15 Nov 2026 14:14:14 +0200 Subject: [PATCH] Fixes hidden detection for directory paths with trailing separators. --- .../Services/DirectoryProviderService.cs | 4 +++- .../Services/DirectoryProviderServiceTests.cs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Lumina.Domain/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/DirectoryProviderService.cs b/src/Lumina.Domain/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/DirectoryProviderService.cs index 214ca1e6..e248cf19 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/DirectoryProviderService.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/DirectoryProviderService.cs @@ -62,7 +62,9 @@ internal class DirectoryProviderService : IDirectoryProviderService // The hidden flag is metadata, so it follows the same read properties permission as the other metadata accessors. if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false)) return false; - return (GetAttributes(path.Path) & FileAttributes.Hidden) == FileAttributes.Hidden; + // Child directory paths carry a trailing separator, which prevents the Unix file system from reporting the dot-prefixed hidden entry. + string directoryPath = path.Path.EndsWith(_fileSystem.Path.DirectorySeparatorChar) ? path.Path[..^1] : path.Path; + return (GetAttributes(directoryPath) & FileAttributes.Hidden) == FileAttributes.Hidden; } /// diff --git a/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/DirectoryProviderServiceTests.cs b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/DirectoryProviderServiceTests.cs index cd8fd741..2e912756 100644 --- a/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/DirectoryProviderServiceTests.cs +++ b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/DirectoryProviderServiceTests.cs @@ -226,6 +226,22 @@ public class DirectoryProviderServiceTests Assert.True(result); } + [Fact] + public void IsHidden_WhenDirectoryPathEndsWithSeparator_ShouldCheckAttributesWithoutSeparator() + { + // Arrange + FileSystemPathId path = _fileSystemPathIdFixture.Create(_pathHidden2); + _mockFileSystem.Path.DirectorySeparatorChar.Returns(_dirSeparator); + _mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false).Returns(true); + _mockFileSystem.File.GetAttributes(_pathHidden1).Returns(FileAttributes.Directory | FileAttributes.Hidden); + + // Act + bool result = _sut.IsHidden(path); + + // Assert + Assert.True(result); + } + [Fact] public void IsHidden_WhenDirectoryDoesNotHaveHiddenAttribute_ShouldReturnFalse() {