summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent dot torri at gmail dot com>2015-09-29 23:37:46 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-10-19 14:48:49 -0700
commitcb83f1477fe8c2eae823d963b988f5bdcbe8ff86 (patch)
tree1b89bcdf47318c219660cec8bf305246da33b3c2
parent5a3fb40b4c0d3c69a6f73fdb0201173ecc25605f (diff)
efreet: use eina_file_mkstemp() for portability and fix a bug on Windows
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/bin/efreet/efreetd_cache.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/bin/efreet/efreetd_cache.c b/src/bin/efreet/efreetd_cache.c
index a2ef783db8..e3aeb13f70 100644
--- a/src/bin/efreet/efreetd_cache.c
+++ b/src/bin/efreet/efreetd_cache.c
@@ -162,9 +162,9 @@ static void
162subdir_cache_save(void) 162subdir_cache_save(void)
163{ 163{
164 char buf[PATH_MAX], buf2[PATH_MAX]; 164 char buf[PATH_MAX], buf2[PATH_MAX];
165 int tmpfd;
166 mode_t um;
167 Eet_File *ef; 165 Eet_File *ef;
166 Eina_Tmpstr *tmpstr = NULL;
167 int tmpfd;
168 168
169 // only if subdirs need saving... and we have subdirs. 169 // only if subdirs need saving... and we have subdirs.
170 if (!subdir_need_save) return; 170 if (!subdir_need_save) return;
@@ -172,16 +172,24 @@ subdir_cache_save(void)
172 if (!subdir_cache->dirs) return; 172 if (!subdir_cache->dirs) return;
173 173
174 // save to tmp file first 174 // save to tmp file first
175 snprintf(buf2, sizeof(buf2), "%s/efreet/subdirs_%s.eet.XXXXXX", efreet_cache_home_get(), efreet_hostname_get()); 175 snprintf(buf2, sizeof(buf2), "%s/efreet/subdirs_%s.eet.XXXXXX.cache", efreet_cache_home_get(), efreet_hostname_get());
176 um = umask(0077); 176 tmpfd = eina_file_mkstemp(buf2, &tmpstr);
177 tmpfd = mkstemp(buf2);
178 umask(um);
179 if (tmpfd < 0) return; 177 if (tmpfd < 0) return;
180 178
181 // write out eetf ile to tmp file 179 // write out eet file to tmp file
182 ef = eet_open(buf2, EET_FILE_MODE_WRITE); 180 ef = eet_open(buf2, EET_FILE_MODE_WRITE);
183 eet_data_write(ef, subdir_edd, "subdirs", subdir_cache, EET_COMPRESSION_SUPERFAST); 181 eet_data_write(ef, subdir_edd, "subdirs", subdir_cache, EET_COMPRESSION_SUPERFAST);
184 eet_close(ef); 182 eet_close(ef);
183 eina_tmpstr_del(tmpstr);
184
185 /*
186 * On Windows, buf2 has one remaining ref, hence it can not be renamed below.
187 * Stupid NTFS... So we close it first. "Magically", on Windows, this
188 * temporary file is not deleted...
189 */
190#ifdef _WIN32
191 close(tmpfd);
192#endif
185 193
186 // atomically rename subdirs file on top from tmp file 194 // atomically rename subdirs file on top from tmp file
187 snprintf(buf, sizeof(buf), "%s/efreet/subdirs_%s.eet", efreet_cache_home_get(), efreet_hostname_get()); 195 snprintf(buf, sizeof(buf), "%s/efreet/subdirs_%s.eet", efreet_cache_home_get(), efreet_hostname_get());