Page MenuHomePhabricator

Native-Windows: `unlink` needs all references to the file to be already closed
Open, Incoming QueuePublic

Description

Windows unlink works differently than the Linux version, as stated by unlink man page:

If one or more processes have the file open when the last link is removed, the link shall be removed before unlink() returns, but the removal of the file contents shall be postponed until all references to the file are closed.

But on Windows, it needs every reference to the file to be closed before calling it, otherwise, it returns -1, leaving the file be.

This may cause some problems to the user as they have to know which platform their code will run to correctly flush the file if needed.

For example, if they are using eet to manage some temporary files, as eet_close is postponed in some cases, they have to flush the file with eet_clearcache before unlink to successfully delete the file.

For reference, src/tests/eet/eet_test_image.c:eet_test_image_small is a slim test that demostrat this, as the last eet_open is for a read, eet_close is postponed, thus unlink can't remove the file on Windows.

lucas created this task.Aug 25 2020, 8:07 AM
lucas added a comment.Sep 1 2020, 9:00 AM

eina has an alternative to unlink that manages open references: eina_file_unlink.
So using it instead of unlink seems like a viable solution/workaround.