Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer Posix-style file and directory deletion APIs #32737

Closed
GSPP opened this issue Feb 24, 2020 · 4 comments
Closed

Offer Posix-style file and directory deletion APIs #32737

GSPP opened this issue Feb 24, 2020 · 4 comments

Comments

@GSPP
Copy link

GSPP commented Feb 24, 2020

It seems that recent versions of Windows offer the ability to immediately delete "POSIX style": https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/ns-ntddk-_file_disposition_information_ex

This means that file deletion is fully synchronous. The name for the file is deleted while open handles can still exist.

Asynchronous file deletion on Windows is a fairly common pain-point, for example: PowerShell/PowerShell#8211 (related: #27958).

The MSVC STL implementation uses synchronous deletion if available: https://github.com/BillyONeal/STL/blob/ece92443331ad03eb70ee1824dad87165b410e97/stl/src/filesystem.cpp#L655

There is a fallback for situations in which this deletion style is not supported. According to microsoft/STL#407 it seems that ReFS does not support this.

Here is a discussion of a case where this feature was used to delete something that otherwise could not be deleted at all: https://community.osr.com/discussion/286551


This seems like a useful feature to have. .NET should offer an API for this. This could take the form of a new enum:

[Flags]
enum FileSystemDeletionOptions
{
 None = 0,
 PosixSemantics = 1,
}

This enum could hold further features such as the commonly requested ability to delete readonly files or the ability to ignore the situation where the target does not exist.

@stephentoub
Copy link
Member

stephentoub commented Feb 24, 2020

cc: @JeremyKuhne, who's looked at this in detail.

@JeremyKuhne
Copy link
Member

The Posix style deletion is the default now, we have tests that validate that. There might be edge cases here and I believe there was an intent to provide a compat switch, but I'm not sure where that lives- I'll see if I can find more details.

We should consider adding the ability to disable the new behavior, but I suspect that need is fairly narrow.

cc: @carlossanlop

@JeremyKuhne
Copy link
Member

Triage: Closing as Posix style deletion is the default now in Windows 10 (as of 1903).

@JeremyKuhne JeremyKuhne removed the untriaged New issue has not been triaged by the area owner label Mar 5, 2020
@mklement0
Copy link

Note:

  • The following update is based on running the Assert-ReliableDirRemoval .net test above successfully in Windows 10 version 20H2 and the information gleaned from this Stack Overflow post.

  • As of this writing, the documentation of the underlying DeleteFile Windows API makes no mention of the change in behavior.


Starting with Windows 10 version 1909, (at least) build 18363.657 (I don't know that Windows Server version and build that corresponds to; run winver.exe to check your version and build), the DeleteFile Windows API function now exhibits synchronous behavior at the Windows API level, which implicitly solves the problems with PowerShell's Remove-Item and .NET's System.IO.File.Delete / System.IO.Directory.Delete (but, curiously, not with cmd.exe's rd /s).

@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants