forked from enlightenment/edi
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:
parent
bdde32ba88
commit
3ec3d476fd
|
@ -1,5 +1,6 @@
|
||||||
#include "Edi.h"
|
#include "Edi.h"
|
||||||
#include "edi_file.h"
|
#include "edi_file.h"
|
||||||
|
#include "edi_config.h"
|
||||||
#include "edi_private.h"
|
#include "edi_private.h"
|
||||||
|
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
|
@ -23,10 +24,14 @@ edi_file_text_replace(const char *path, const char *search, const char *replace)
|
||||||
char *map, *found;
|
char *map, *found;
|
||||||
FILE *tempfile;
|
FILE *tempfile;
|
||||||
Eina_File *f;
|
Eina_File *f;
|
||||||
char tempfilepath[PATH_MAX];
|
char *tempfiledir, *tempfilepath;
|
||||||
unsigned long long len, idx;
|
unsigned long long len, idx;
|
||||||
unsigned int slen;
|
unsigned int slen;
|
||||||
|
|
||||||
|
tempfiledir = edi_path_append(_edi_config_dir_get(), ".tmp");
|
||||||
|
|
||||||
|
ecore_file_mkdir(tempfiledir);
|
||||||
|
|
||||||
f = eina_file_open(path, EINA_FALSE);
|
f = eina_file_open(path, EINA_FALSE);
|
||||||
if (!f) return;
|
if (!f) return;
|
||||||
|
|
||||||
|
@ -44,7 +49,7 @@ edi_file_text_replace(const char *path, const char *search, const char *replace)
|
||||||
return;
|
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");
|
tempfile = fopen(tempfilepath, "wb");
|
||||||
if (!tempfile) goto done;
|
if (!tempfile) goto done;
|
||||||
|
@ -78,9 +83,11 @@ edi_file_text_replace(const char *path, const char *search, const char *replace)
|
||||||
|
|
||||||
fclose(tempfile);
|
fclose(tempfile);
|
||||||
ecore_file_mv(tempfilepath, path);
|
ecore_file_mv(tempfilepath, path);
|
||||||
|
free(tempfilepath);
|
||||||
done:
|
done:
|
||||||
eina_file_map_free(f, map);
|
eina_file_map_free(f, map);
|
||||||
eina_file_close(f);
|
eina_file_close(f);
|
||||||
|
free(tempfiledir);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue