cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=cb83f1477fe8c2eae823d963b988f5bdcbe8ff86

commit cb83f1477fe8c2eae823d963b988f5bdcbe8ff86
Author: Vincent Torri <vincent dot torri at gmail dot com>
Date:   Tue Sep 29 23:37:46 2015 +0200

    efreet: use eina_file_mkstemp() for portability and fix a bug on Windows
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 src/bin/efreet/efreetd_cache.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/bin/efreet/efreetd_cache.c b/src/bin/efreet/efreetd_cache.c
index a2ef783..e3aeb13 100644
--- a/src/bin/efreet/efreetd_cache.c
+++ b/src/bin/efreet/efreetd_cache.c
@@ -162,9 +162,9 @@ static void
 subdir_cache_save(void)
 {
    char buf[PATH_MAX], buf2[PATH_MAX];
-   int tmpfd;
-   mode_t um;
    Eet_File *ef;
+   Eina_Tmpstr *tmpstr = NULL;
+   int tmpfd;
 
    // only if subdirs need saving... and we have subdirs.
    if (!subdir_need_save) return;
@@ -172,16 +172,24 @@ subdir_cache_save(void)
    if (!subdir_cache->dirs) return;
 
    // save to tmp file first
-   snprintf(buf2, sizeof(buf2), "%s/efreet/subdirs_%s.eet.XXXXXX", 
efreet_cache_home_get(), efreet_hostname_get());
-   um = umask(0077);
-   tmpfd = mkstemp(buf2);
-   umask(um);
+   snprintf(buf2, sizeof(buf2), "%s/efreet/subdirs_%s.eet.XXXXXX.cache", 
efreet_cache_home_get(), efreet_hostname_get());
+   tmpfd = eina_file_mkstemp(buf2, &tmpstr);
    if (tmpfd < 0) return;
 
-   // write out eetf ile to tmp file
+   // write out eet file to tmp file
    ef = eet_open(buf2, EET_FILE_MODE_WRITE);
    eet_data_write(ef, subdir_edd, "subdirs", subdir_cache, 
EET_COMPRESSION_SUPERFAST);
    eet_close(ef);
+   eina_tmpstr_del(tmpstr);
+
+   /*
+    * On Windows, buf2 has one remaining ref, hence it can not be renamed 
below.
+    * Stupid NTFS... So we close it first. "Magically", on Windows, this
+    * temporary file is not deleted...
+    */
+#ifdef _WIN32
+   close(tmpfd);
+#endif
 
    // atomically rename subdirs file on top from tmp file
    snprintf(buf, sizeof(buf), "%s/efreet/subdirs_%s.eet", 
efreet_cache_home_get(), efreet_hostname_get());

-- 


Reply via email to