Skip to content

Move a readonly file results in inconsistent state #870

Closed

Description

@vbreuss

Describe the bug
Moving a readonly file throws (correctly) an UnauthorizedAccessException, but afterwards both the source file and also the target file exist.

To Reproduce
Consider the following unit test (using Xunit and FluentAssertions):

    [Fact]
    public void MoveFile_WithReadOnlyAttribute_ShouldThrowExceptionAndNotMoveFile()
    {
      var sut = new MockFileSystem();
      sut.File.WriteAllText("foo.txt", "xyz");
      sut.File.SetAttributes("foo.txt", FileAttributes.ReadOnly);
      
      var exception = Record.Exception(() =>
      {
        sut.File.Move("foo.txt", "bar.txt");
      });

      exception.Should().BeAssignableTo<UnauthorizedAccessException>();
      sut.File.Exists("foo.txt").Should().BeTrue();
      sut.File.Exists("bar.txt").Should().BeFalse();
    }

This test fails at the last line, as the file exists now twice, resulting in an inconsistent state of the MockFileSystem

Expected behavior
The unit test should be successful.

Additional context
This issue might have similar root cause as #849 ?

Activity

  1. vbreuss commented on Aug 9, 2022

    @vbreuss
    MemberAuthor

    I would be happy to provide a solution for this issue myself. Will create a pull request shortly...

  2. added a commit that references this issue on Aug 9, 2022
    c757dbb
  3. added
    state: in workIssues that are currently worked on
    and removed on Aug 9, 2022
  4. added 2 commits that reference this issue on Aug 10, 2022
    3de0256
    a008c15
  5. added a commit that references this issue on Aug 15, 2022
    df30ba4
  6. github-actions commented on Aug 15, 2022

    @github-actions

    This is addressed in release v17.0.28.

  7. added a commit that references this issue on Aug 26, 2022
    1fd96ca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: testinghelpersIssues that address the testing helpersstate: in workIssues that are currently worked onstate: releasedIssues that are releasedtype: bugIssues that describe misbehaving functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions