move batch directory creation to ecore_file.

as suggested by raster, this could be abstracted into ecore-file and
other applications could use it as well.



SVN revision: 39965
This commit is contained in:
Gustavo Sverzut Barbieri 2009-04-11 07:10:12 +00:00
parent 51eff88b13
commit 886a0bca01
2 changed files with 7 additions and 92 deletions

View File

@ -29,27 +29,6 @@ AC_PROG_LIBTOOL
AC_CHECK_FUNCS(setenv)
AC_CHECK_FUNCS(unsetenv)
have_atfile_source=auto
AC_ARG_ENABLE(atfile-source,
AC_HELP_STRING([--disable-atfile-source],
[disable use of atfile source functions as openat and mkdirat @<:@default=detect@:>@]),
[have_atfile_source=$enableval], [have_atfile_source=auto])
if test "x$have_atfile_source" != "xno"; then
AC_CHECK_FUNCS(mkdirat,
[
have_atfile_source=yes
AC_DEFINE(HAVE_ATFILE_SOURCE, 1, [mkdirat exists])
],
[
if test "x$have_atfile_source" = "xyes"; then
AC_MSG_ERROR([required atfile-source but no mkdirat()])
fi
have_atfile_source=no
])
fi
AC_CHECK_HEADERS(fnmatch.h,, AC_MSG_ERROR([Cannot find fnmatch.h. Make sure your CFLAGS environment variable contains include lines for the location of this file]))
AC_CHECK_FUNCS(fnmatch, res=yes, res=no)

View File

@ -1166,8 +1166,6 @@ _e_main_x_shutdown(void)
return 1;
}
static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
static int
_e_main_dirs_init(void)
{
@ -1191,10 +1189,10 @@ _e_main_dirs_init(void)
"modules",
"config",
"locale",
"input_methods"
"input_methods",
NULL
};
int i, fd, baselen, retval;
DIR *dir;
int baselen;
homedir = e_user_homedir_get();
baselen = snprintf(buf, sizeof(buf), "%s/.e/e", homedir);
@ -1204,76 +1202,14 @@ _e_main_dirs_init(void)
homedir);
return 0;
}
if ((!ecore_file_is_dir(buf)) && (!ecore_file_mkpath(buf)))
if (ecore_file_mksubdirs(buf, dirs) != sizeof(dirs)/sizeof(dirs[0]) - 1)
{
e_error_message_show("Error creating directory:\n%s", buf);
e_error_message_show
("Could not create one of the required subdirectories of '%s'", buf);
return 0;
}
dir = opendir(buf);
if (!dir)
{
e_error_message_show("Could not open:\n%s\nError: %s",
buf, strerror(errno));
return 0;
}
fd = dirfd(dir);
buf[baselen] = '/';
baselen++;
buf[baselen] = '\0';
retval = 1;
for (i = 0; i < (int)(sizeof(dirs) / sizeof(char *)); i++)
{
struct stat st;
#ifndef HAVE_ATFILE_SOURCE
ecore_strlcpy(buf + baselen, dirs[i], sizeof(buf) - baselen);
if (stat(buf, &st) == 0)
#else
if (fstatat(fd, dirs[i], &st, 0) == 0)
#endif
{
if (S_ISDIR(st.st_mode))
continue;
else
{
e_error_message_show("Not a directory:\n%s%s", buf, dirs[i]);
retval = 0;
goto end;
}
}
else
{
if (errno == ENOENT)
{
#ifndef HAVE_ATFILE_SOURCE
if (mkdir(buf, default_mode) == 0)
#else
if (mkdirat(fd, dirs[i], default_mode) == 0)
#endif
continue;
else
{
e_error_message_show
("could not create dir:\n%s%s\nError: %s",
buf, dirs[i], strerror(errno));
retval = 0;
goto end;
}
}
else
{
e_error_message_show("could not fstat:\n%s%s\nError: %s",
buf, dirs[i], strerror(errno));
retval = 0;
goto end;
}
}
}
end:
closedir(dir);
return retval;
return 1;
}
static int