Skip to content

fix: Throw IOException when deleting current directory #939

@pw-sgr

Description

@pw-sgr

dotnet has a handle on the current working directory, this will prevent deletion of any part of it.
Since we have the current working dir in the mock, we can support at least this handle

var fileSystem = new MockFileSystem();
string path = fileSystem.Path.Combine(fileSystem.Path.GetTempPath(), "my-test");
fileSystem.Directory.CreateDirectory(path);
fileSystem.Directory.SetCurrentDirectory(path);
fileSystem.Directory.Delete(fileSystem.Directory.GetCurrentDirectory());
fileSystem.Directory.SetCurrentDirectory(fileSystem.Directory.GetCurrentDirectory());

Expected:
System.IO.IOException : The process cannot access the file '\\?\<Some dir that exists>' because it is being used by another process.

Actual:
Nothing, can delete the current working dir on the mock, but not on the actual file system
Will then throw it can't find the dir on the second SetCurrentDirectory

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions