mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Allows renaming files that are not executable on Unix
This commit is contained in:
1 parent
114bfe94ff
commit
f14b321294
2 files changed
+1
-31
No files matched your search
+1
-3
@@ -247,9 +247,7 @@ internal class FileProviderService : IFileProviderService
|
||||
Result<FileSystemPathId> 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);
|
||||
|
||||
-28
@@ -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<FileSystemPathId>(), FileAccessMode.Write).Returns(true);
|
||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Execute).Returns(true);
|
||||
|
||||
// Act
|
||||
Result<FileSystemPathId> result = _sut.RenameFile(path, newName);
|
||||
@@ -737,33 +736,6 @@ public class FileProviderServiceTests
|
||||
_mockFileSystem.File.DidNotReceive().Move(Arg.Any<string>(), Arg.Any<string>());
|
||||
}
|
||||
|
||||
[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<IFileInfo>();
|
||||
fileInfo.DirectoryName.Returns(parentPath);
|
||||
_mockFileSystem.FileInfo.New(path.Path).Returns(fileInfo);
|
||||
_mockFileSystem.Path.Combine(parentPath, newName).Returns(newPath);
|
||||
_mockFileSystemPermissionsService.CanAccessPath(Arg.Any<FileSystemPathId>(), FileAccessMode.Write).Returns(true);
|
||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Execute).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<FileSystemPathId> result = _sut.RenameFile(path, newName);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Permission.UnauthorizedAccess, result.FirstError);
|
||||
_mockFileSystem.File.DidNotReceive().Move(Arg.Any<string>(), Arg.Any<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RenameFile_WhenParentDirectoryIsNull_ShouldReturnInvalidPathError()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user