mirror of https://github.com/djcb/mu.git
* mu-util.[ch]: add mu_util_check_dir (to check for
existence/readability/writability of dirs
This commit is contained in:
parent
39192b7a42
commit
3b1b4926bf
|
@ -54,18 +54,31 @@ mu_util_dir_expand (const char *path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
gboolean
|
||||||
static gboolean
|
mu_util_check_dir (const gchar* path, gboolean readable, gboolean writeable)
|
||||||
_is_readable_dir (const gchar* path)
|
|
||||||
{
|
{
|
||||||
|
mode_t mode;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
|
if (!path)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
mode = F_OK | (readable ? R_OK : 0) | (writeable ? W_OK : 0);
|
||||||
|
|
||||||
return path &&
|
if (access (path, mode) != 0) {
|
||||||
access (path, R_OK) == 0 &&
|
MU_WRITE_LOG ("Cannot access %s: %s", path, strerror (errno));
|
||||||
stat (path, &statbuf) == 0 &&
|
return FALSE;
|
||||||
S_ISDIR(statbuf.st_mode);
|
}
|
||||||
|
|
||||||
|
if (stat (path, &statbuf) != 0) {
|
||||||
|
MU_WRITE_LOG ("Cannot stat %s: %s", path, strerror (errno));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return S_ISDIR(statbuf.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
mu_util_guess_maildir (void)
|
mu_util_guess_maildir (void)
|
||||||
{
|
{
|
||||||
|
@ -73,12 +86,12 @@ mu_util_guess_maildir (void)
|
||||||
|
|
||||||
/* first, try MAILDIR */
|
/* first, try MAILDIR */
|
||||||
dir = getenv ("MAILDIR");
|
dir = getenv ("MAILDIR");
|
||||||
if (_is_readable_dir (dir))
|
if (mu_util_check_dir (dir, TRUE, FALSE))
|
||||||
return g_strdup (dir);
|
return g_strdup (dir);
|
||||||
|
|
||||||
/* then, try ~/Maildir */
|
/* then, try ~/Maildir */
|
||||||
dir = mu_util_dir_expand ("~/Maildir");
|
dir = mu_util_dir_expand ("~/Maildir");
|
||||||
if (_is_readable_dir (dir))
|
if (!mu_util_check_dir (dir, TRUE, FALSE))
|
||||||
return dir;
|
return dir;
|
||||||
|
|
||||||
/* nope; nothing found */
|
/* nope; nothing found */
|
||||||
|
@ -86,6 +99,7 @@ mu_util_guess_maildir (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mu_util_create_dir_maybe (const gchar *path)
|
mu_util_create_dir_maybe (const gchar *path)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue