From f14b321294e5a90160ac591d468085bfd2747a46 Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Sun, 6 Sep 2026 10:43:34 -0700 Subject: [PATCH] Allows renaming files that are not executable on Unix --- .../Services/FileProviderService.cs | 4 +-- .../Services/FileProviderServiceTests.cs | 28 ------------------- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/src/Lumina.Domain/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/FileProviderService.cs b/src/Lumina.Domain/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/FileProviderService.cs index 84eb7e05..452e3667 100644 --- a/src/Lumina.Domain/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/FileProviderService.cs +++ b/src/Lumina.Domain/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/FileProviderService.cs @@ -247,9 +247,7 @@ internal class FileProviderService : IFileProviderService Result newFilePathResult = FileSystemPathId.Create(newFile); if (newFilePathResult.IsFailure) return newFilePathResult.Errors; - // check if the user has access permissions to the provided path - if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Execute)) - return Errors.Permission.UnauthorizedAccess; + // renaming a file only requires write access to its parent directory, never execute access to the file itself if (!_fileSystemPermissionsService.CanAccessPath(parendDirectoryResult.Value, FileAccessMode.Write)) return Errors.Permission.UnauthorizedAccess; _fileSystem.File.Move(path.Path, newFilePathResult.Value.Path); diff --git a/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/FileProviderServiceTests.cs b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/FileProviderServiceTests.cs index ab1424a5..8088d6fe 100644 --- a/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/FileProviderServiceTests.cs +++ b/tests/UnitTests/Lumina.Domain.UnitTests/Core/BoundedContexts/FileSystemManagementBoundedContext/FileSystemManagementAggregate/Services/FileProviderServiceTests.cs @@ -700,7 +700,6 @@ public class FileProviderServiceTests _mockFileSystem.FileInfo.New(path.Path).Returns(fileInfo); _mockFileSystem.Path.Combine(parentPath, newName).Returns(newPath); _mockFileSystemPermissionsService.CanAccessPath(Arg.Any(), FileAccessMode.Write).Returns(true); - _mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Execute).Returns(true); // Act Result result = _sut.RenameFile(path, newName); @@ -737,33 +736,6 @@ public class FileProviderServiceTests _mockFileSystem.File.DidNotReceive().Move(Arg.Any(), Arg.Any()); } - [Fact] - public void RenameFile_WhenFileIsNotExecutable_ShouldReturnUnauthorizedAccessError() - { - // Arrange - FileSystemPathId path = _fileSystemPathIdFixture.Create( - s_isUnix ? "/OldName.txt" : @"C:\OldName.txt" - ); - string newName = "NewName.txt"; - string parentPath = s_isUnix ? "/" : @"C:\"; - string newPath = s_isUnix ? "/NewName.txt" : @"C:\NewName.txt"; - - IFileInfo fileInfo = Substitute.For(); - fileInfo.DirectoryName.Returns(parentPath); - _mockFileSystem.FileInfo.New(path.Path).Returns(fileInfo); - _mockFileSystem.Path.Combine(parentPath, newName).Returns(newPath); - _mockFileSystemPermissionsService.CanAccessPath(Arg.Any(), FileAccessMode.Write).Returns(true); - _mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Execute).Returns(false); - - // Act - Result result = _sut.RenameFile(path, newName); - - // Assert - Assert.True(result.IsFailure); - Assert.Equal(Errors.Permission.UnauthorizedAccess, result.FirstError); - _mockFileSystem.File.DidNotReceive().Move(Arg.Any(), Arg.Any()); - } - [Fact] public void RenameFile_WhenParentDirectoryIsNull_ShouldReturnInvalidPathError() {