Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ public IStorageAccessHandle RequestAccess(FileAccess access, FileShare share,
!ignoreMetadataErrors &&
Attributes.HasFlag(FileAttributes.ReadOnly))
{
throw ExceptionFactory.AccessToPathDenied();
throw ExceptionFactory.AccessToPathDenied(_fileSystem.Execute.IsNetFramework
? _location.FriendlyName
: _location.FullPath);
}
#if FEATURE_FILESYSTEM_UNIXFILEMODE
if (!deleteAccess && !_fileSystem.UnixFileModeStrategy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public bool DeleteContainer(
location);

using (container.RequestAccess(FileAccess.Write, FileShare.ReadWrite,
ignoreMetadataErrors: false,
deleteAccess: true))
{
if (_containers.TryRemove(location, out IStorageContainer? removed))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ await That(Act).Throws<DirectoryNotFoundException>()
.WithHResult(-2147024893);
}

[Theory]
[AutoData]
public async Task Delete_ReadonlyDirectory_ShouldThrowIOExceptionOnWindows(string path)
{
IDirectoryInfo sut = FileSystem.Directory.CreateDirectory(path);
sut.Attributes = FileAttributes.ReadOnly;
sut.Refresh();

void Act()
{
FileSystem.Directory.Delete(path);
}

await That(Act).Throws<IOException>()
.OnlyIf(Test.RunsOnWindows)
.WithMessage(Test.IsNetFramework
? $"Access to the path '{path}' is denied."
: $"Access to the path '{sut.FullName}' is denied.").And
.WithHResult(-2146232800);
}

[Theory]
[AutoData]
public async Task Delete_Recursive_MissingDirectory_ShouldThrowDirectoryNotFoundException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ await That(Act).Throws<DirectoryNotFoundException>()
.WithHResult(-2147024893);
}

[Theory]
[AutoData]
public async Task Delete_ReadonlyDirectory_ShouldThrowIOExceptionOnWindows(string path)
{
IDirectoryInfo sut = FileSystem.Directory.CreateDirectory(path);
sut.Attributes = FileAttributes.ReadOnly;
sut.Refresh();

void Act()
{
sut.Delete();
}

await That(Act).Throws<IOException>()
.OnlyIf(Test.RunsOnWindows)
.WithMessage(Test.IsNetFramework
? $"Access to the path '{path}' is denied."
: $"Access to the path '{sut.FullName}' is denied.").And
.WithHResult(-2146232800);
}

[Theory]
[AutoData]
public async Task Delete_Recursive_WithOpenFile_ShouldThrowIOException_OnWindows(
Expand Down
Loading