Skip to content

RemoveDirectoryOptions::RemoveReadOnly should remove both read-only files and directories#617

Open
dimhotepus wants to merge 3 commits intomicrosoft:masterfrom
dimhotepus:user/dzmitry/removedirectoryrecursive-readonly-directories
Open

RemoveDirectoryOptions::RemoveReadOnly should remove both read-only files and directories#617
dimhotepus wants to merge 3 commits intomicrosoft:masterfrom
dimhotepus:user/dzmitry/removedirectoryrecursive-readonly-directories

Conversation

@dimhotepus
Copy link
Contributor

@dimhotepus dimhotepus commented Feb 21, 2026

Closes #565


// Fail if the directory does not have read-only set, likely just an ACL problem
DWORD directoryAttr = ::GetFileAttributesW(path.get());
RETURN_LAST_ERROR_IF(!WI_IsFlagSet(directoryAttr, FILE_ATTRIBUTE_READONLY));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably GetLastError won't contain failure because you just called GetFileAttributesW right before this (which probably succeeded). And even if it did fail, you probably want the original error from the call to RemoveDirectoryW

Comment on lines +395 to +398
if (directoryAttr == 0)
{
directoryAttr = FILE_ATTRIBUTE_NORMAL;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Presumably the attributes have FILE_ATTRIBUTE_DIRECTORY set at a minimum.

@dunhor
Copy link
Member

dunhor commented Feb 24, 2026

@ChrisGuzak and @jonwis for their thoughts.

This jumps out as potentially concerning because it's changing behavior of something that an existing application could theoretically be depending on. The safest route would be to introduce a new flag - RemoveDirectoryOptions::RemoveReadOnlyDirectory - and possibly add a new RemoveDirectoryOptions::RemoveReadOnlyFile that aliases RemoveDirectoryOptions::RemoveReadOnly.

That said, looking around at existing uses of RemoveDirectoryOptions::RemoveReadOnly, there doesn't appear to be that many instances outside of test code, so this might just be okay.

@dunhor
Copy link
Member

dunhor commented Feb 24, 2026

The impact is presumably limited to just the directories themselves, so all of the directory contents would still get deleted, so the impact from, say, a security perspective, seems low.

@jonwis
Copy link
Member

jonwis commented Feb 25, 2026

Yeah, I like that additional flag for "... and your little readonly dirs, too!" mode. Thanks for the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RemoveDirectoryRecursive fails if directory has read-only attribute

3 participants