mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 19:21:10 +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);
|
Result<FileSystemPathId> newFilePathResult = FileSystemPathId.Create(newFile);
|
||||||
if (newFilePathResult.IsFailure)
|
if (newFilePathResult.IsFailure)
|
||||||
return newFilePathResult.Errors;
|
return newFilePathResult.Errors;
|
||||||
// check if the user has access permissions to the provided path
|
// renaming a file only requires write access to its parent directory, never execute access to the file itself
|
||||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Execute))
|
|
||||||
return Errors.Permission.UnauthorizedAccess;
|
|
||||||
if (!_fileSystemPermissionsService.CanAccessPath(parendDirectoryResult.Value, FileAccessMode.Write))
|
if (!_fileSystemPermissionsService.CanAccessPath(parendDirectoryResult.Value, FileAccessMode.Write))
|
||||||
return Errors.Permission.UnauthorizedAccess;
|
return Errors.Permission.UnauthorizedAccess;
|
||||||
_fileSystem.File.Move(path.Path, newFilePathResult.Value.Path);
|
_fileSystem.File.Move(path.Path, newFilePathResult.Value.Path);
|
||||||
|
|||||||
-28
@@ -700,7 +700,6 @@ public class FileProviderServiceTests
|
|||||||
_mockFileSystem.FileInfo.New(path.Path).Returns(fileInfo);
|
_mockFileSystem.FileInfo.New(path.Path).Returns(fileInfo);
|
||||||
_mockFileSystem.Path.Combine(parentPath, newName).Returns(newPath);
|
_mockFileSystem.Path.Combine(parentPath, newName).Returns(newPath);
|
||||||
_mockFileSystemPermissionsService.CanAccessPath(Arg.Any<FileSystemPathId>(), FileAccessMode.Write).Returns(true);
|
_mockFileSystemPermissionsService.CanAccessPath(Arg.Any<FileSystemPathId>(), FileAccessMode.Write).Returns(true);
|
||||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Execute).Returns(true);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<FileSystemPathId> result = _sut.RenameFile(path, newName);
|
Result<FileSystemPathId> result = _sut.RenameFile(path, newName);
|
||||||
@@ -737,33 +736,6 @@ public class FileProviderServiceTests
|
|||||||
_mockFileSystem.File.DidNotReceive().Move(Arg.Any<string>(), Arg.Any<string>());
|
_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]
|
[Fact]
|
||||||
public void RenameFile_WhenParentDirectoryIsNull_ShouldReturnInvalidPathError()
|
public void RenameFile_WhenParentDirectoryIsNull_ShouldReturnInvalidPathError()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user