The main temporary file not delete on Lzma mode
larrylau opened this issue · 3 comments
The main program will extract On the lzma mode, but The temporary file not delete on exit!
Thanks for reporting this. Are you using Windows by any chance? My guess is that the unlink call at https://github.com/ReadyTalk/avian/blob/836cc4/src/lzma/load.cpp#L153 isn't working because Windows doesn't allow deleting a file while it is loaded as a library.
One possible solution would be to explicitly unload the library and unlink it after mainFunction returns at https://github.com/ReadyTalk/avian/blob/836cc4/src/lzma/load.cpp#L160. I don't have a machine with Windows handy at the moment to try that, but that's what I would recommend.
I used mingw on win7, consider win32api Createfile with flag FILE_FLAG_DELETE_ON_CLOSE ?
@larrylau - Something like that will probably work, although you'll likely have to write the file (per the current method), close that handle, then open the handle again with GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, and FILE_FLAG_DELETE_ON_CLOSE.
CreateProcess will refuse to load a module with writable handles open to it (or indeed, handles that specify FILE_SHARE_WRITE, IIRC), and I'm assuming LoadLibrary will behave similarly.