exactness: factor out the special _mkdir() handling

We have an ecore function to handle most of this already. For the case
where we give a file name cut off that part before handing it off to
creation.

Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Differential Revision: https://phab.enlightenment.org/D11458
This commit is contained in:
Stefan Schmidt 2020-03-17 17:08:40 +01:00
parent b84694f518
commit 2754bc93e6
2 changed files with 8 additions and 45 deletions

View File

@ -803,27 +803,6 @@ _src_open()
return EINA_TRUE;
}
static Eina_Bool
_mkdir(const char *path, Eina_Bool skip_last)
{
if (!ecore_file_exists(path))
{
const char *cur = path + 1;
do
{
char *slash = strchr(cur, '/');
if (slash) *slash = '\0';
else if (skip_last) return EINA_TRUE;
if (!ecore_file_exists(path) && !ecore_file_mkdir(path)) return EINA_FALSE;
if (slash) *slash = '/';
if (slash) cur = slash + 1;
else cur = NULL;
}
while (cur);
}
return EINA_TRUE;
}
static void
_old_shots_rm_cb(const char *name, const char *path, void *data)
{
@ -988,16 +967,20 @@ int main(int argc, char **argv)
if (!strcmp(_dest + strlen(_dest) - 4,".exu"))
{
_dest_type = FTYPE_EXU;
if (!_mkdir(_dest, EINA_TRUE))
/* Cut path at the beginning of the file name */
char *file_start = strrchr(dest, '/');
*file_start = '\0';
if (!ecore_file_mkpath(dest))
{
fprintf(stderr, "Path for %s cannot be created\n", _dest);
fprintf(stderr, "Path for %s cannot be created\n", dest);
goto end;
}
}
else
{
_dest_type = FTYPE_DIR;
if (!_mkdir(_dest, EINA_FALSE))
if (!ecore_file_mkpath(_dest))
{
fprintf(stderr, "Directory %s cannot be created\n", _dest);
goto end;

View File

@ -235,26 +235,6 @@ _my_evas_new(int w EINA_UNUSED, int h EINA_UNUSED)
return e;
}
static Eina_Bool
_mkdir(const char *dir)
{
if (!ecore_file_exists(dir))
{
const char *cur = dir + 1;
do
{
char *slash = strchr(cur, '/');
if (slash) *slash = '\0';
if (!ecore_file_exists(dir) && !ecore_file_mkdir(dir)) return EINA_FALSE;
if (slash) *slash = '/';
if (slash) cur = slash + 1;
else cur = NULL;
}
while (cur);
}
return EINA_TRUE;
}
static const Ecore_Getopt optdesc = {
"exactness_record",
"%prog [options] <-v|-t|-h> command",
@ -343,7 +323,7 @@ int main(int argc, char **argv)
if (slash)
{
*slash = '\0';
if (!_mkdir(_out_filename))
if (!ecore_file_mkpath(_out_filename))
{
fprintf(stderr, "Can't create %s\n", _out_filename);
goto end;