Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to remove FILE_FLAG_DELETE_ON_CLOSE?

Tags:

file

winapi

in my app I'd like to open a temp file with FILE_FLAG_DELETE_ON_CLOSE. however there are some cases where the temp file needs to be kept and is quite large

I'd like to remove the FILE_FLAG_DELETE_ON_CLOSE attribute on an opened handle? is this possible? copying the contents of the file or renaming isnt quite what I want, I'd like to remove the attribute. this is due to how i'm transacting some writes, in my app closing the handle will open me up to a race condition

like image 318
stuck Avatar asked Feb 27 '23 08:02

stuck


2 Answers

You could do it the other way around. Open the file first, specifying FILE_SHARE_DELETE. Then, when you need to close the file, open it again with FILE_DELETE_ON_CLOSE, then close both handles. Or, just close it, and it won't be deleted.

like image 171
Chris Becke Avatar answered Feb 28 '23 22:02

Chris Becke


No, it's not possible once you've done the create. A dangerous idea might start with the statement, "That flag is only relevant to the handle the link was opened on." So creating a new link might "fix" it. I haven't thought about that more than five seconds, but it's the only slightly clever thing coming to me at midnight.

like image 34
jrtipton Avatar answered Feb 28 '23 22:02

jrtipton