edi_file: replace. use a local temp directory rather than /tmp.

This is firstly more portable and also some distrbutors won't allow
us to move from /tmp (wise).
This commit is contained in:
Al Poole 2017-10-21 14:05:13 +01:00
parent bdde32ba88
commit 3ec3d476fd
1 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,6 @@
#include "Edi.h"
#include "edi_file.h"
#include "edi_config.h"
#include "edi_private.h"
Eina_Bool
@ -23,10 +24,14 @@ edi_file_text_replace(const char *path, const char *search, const char *replace)
char *map, *found;
FILE *tempfile;
Eina_File *f;
char tempfilepath[PATH_MAX];
char *tempfiledir, *tempfilepath;
unsigned long long len, idx;
unsigned int slen;
tempfiledir = edi_path_append(_edi_config_dir_get(), ".tmp");
ecore_file_mkdir(tempfiledir);
f = eina_file_open(path, EINA_FALSE);
if (!f) return;
@ -44,7 +49,7 @@ edi_file_text_replace(const char *path, const char *search, const char *replace)
return;
}
snprintf(tempfilepath, sizeof(tempfilepath), "/tmp/%s.tmp", ecore_file_file_get(path));
tempfilepath = edi_path_append(tempfiledir, ecore_file_file_get(path));
tempfile = fopen(tempfilepath, "wb");
if (!tempfile) goto done;
@ -78,9 +83,11 @@ edi_file_text_replace(const char *path, const char *search, const char *replace)
fclose(tempfile);
ecore_file_mv(tempfilepath, path);
free(tempfilepath);
done:
eina_file_map_free(f, map);
eina_file_close(f);
free(tempfiledir);
}
static void