eina: Replace remove with rmdir and delete tmpstr
authorJoão Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>
Mon, 24 Aug 2020 16:52:43 +0000 (16:52 +0000)
committerJongmin Lee <jm105.lee@samsung.com>
Mon, 31 Aug 2020 21:28:34 +0000 (06:28 +0900)
Although the [remove manpage](https://linux.die.net/man/3/remove) states that `remove(...)` deletes
either a file or a directory, this is not true in Windows as it can be seen in
[MSDN docs for
remove](https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/remove-wremove?view=vs-2019):

> **(Function description)**
>
> Delete a file.
>
> **Return Value**
>
> Each of these functions returns 0 if the file is successfully deleted.
> Otherwise, **it returns -1 and sets errno either to EACCES to indicate that the
> path** specifies a read-only file, //**specifies a directory**//, or the file
> is open, or to ENOENT to indicate that the filename or path was not found.

This implementation detail caused the Eina test to fail and not removing the
temporary directory.

This patch changes the use of `remove` to the directory-specific `rmdir`, which
is guaranteed to remove the directory. Additionally, it also deletes the
Eina_TmpStr that holds the temporary directory path.

Reviewed-by: Vincent Torri <vincent.torri@gmail.com>
Reviewed-by: Stefan Schmidt <stefan@datenfreihafen.org>
Differential Revision: https://phab.enlightenment.org/D12115

src/tests/eina/eina_test_file.c

index 8a9b13e..f877189 100644 (file)
@@ -849,7 +849,8 @@ EFL_START_TEST(eina_test_file_mktemp)
    eina_iterator_free(it);
 
    fail_if(unlink(tmpfile));
-   fail_if(remove(tmpdir));
+   fail_if(rmdir(tmpdir));
+   eina_tmpstr_del(tmpdir);
 }
 EFL_END_TEST