Fix failed to delete a readonly file on Windows file systems#3542
Fix failed to delete a readonly file on Windows file systems#3542katzyn merged 1 commit intoh2database:masterfrom
Conversation
|
Thank you for your contribution! What is your use case for this operation? Why you need to delete a protected file with H2? |
|
I just run test org.h2.test.store.TestMVStore on Windows, and it failed with exception AccessDeniedException |
|
And Exception stack is shown as follows
|
|
I do not think it's such a good idea. RO flag exist for a reason, and if user decide to remove file, there are tools to do so. |
So only delete file on Windows file systems with AccessDeniedException. |
|
@andreitokar h2database/h2/src/main/org/h2/store/fs/FileUtils.java Lines 323 to 331 in d0d77ae And it doesn't provide any way to reset this flag back. Actually I don't see how it can be reset on POSIX systems, we don't preserve original access permissions on them anywhere. |
|
H2 can set RO flag only on Windows. This flag also prevents deletion on this system. On POSIX systems H2 removes write permissions from owner, group and others instead (ACLs, if any, aren't touched). It doesn't prevent file deletion, H2 was always able to remove read-only files on them. I think older versions of H2 were able to delete read-only files on Windows too, because legacy New versions of H2 use NIO.2 API and this API throws an So this PR is expected to restore consistent behavior of old version of H2. If we don't like it, we can add a new |
If that's the case, and it was a regression, then I take it back, sorry for the noise. |
On Windows file systems, delete a readonly file can cause AccessDeniedException, we should change readonly attribute to false and then delete file