mirror of https://github.com/djcb/mu.git
* mu-maildir.[ch]: make create_maildir work even if the maildir already
partially exists and double-check permissions
This commit is contained in:
parent
dcc0d5fc18
commit
f27af1158b
|
@ -69,15 +69,6 @@ create_maildir (const char *path, mode_t mode, GError **err)
|
||||||
int i;
|
int i;
|
||||||
const gchar* subdirs[] = {"new", "cur", "tmp"};
|
const gchar* subdirs[] = {"new", "cur", "tmp"};
|
||||||
|
|
||||||
/* make sure it does not exist yet */
|
|
||||||
if (access (path, F_OK) == 0)
|
|
||||||
errno = EEXIST;
|
|
||||||
|
|
||||||
if (errno != ENOENT) {
|
|
||||||
g_set_error (err, 0, MU_ERROR_FILE, "%s", strerror (errno));
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(subdirs); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(subdirs); ++i) {
|
||||||
|
|
||||||
const char *fullpath;
|
const char *fullpath;
|
||||||
|
@ -85,10 +76,21 @@ create_maildir (const char *path, mode_t mode, GError **err)
|
||||||
|
|
||||||
/* static buffer */
|
/* static buffer */
|
||||||
fullpath = mu_str_fullpath_s (path, subdirs[i]);
|
fullpath = mu_str_fullpath_s (path, subdirs[i]);
|
||||||
|
|
||||||
|
/* if subdir already exists, don't try to re-create
|
||||||
|
* it */
|
||||||
|
if (mu_util_check_dir (fullpath, TRUE, TRUE))
|
||||||
|
continue;
|
||||||
|
|
||||||
rv = g_mkdir_with_parents (fullpath, (int)mode);
|
rv = g_mkdir_with_parents (fullpath, (int)mode);
|
||||||
if (rv != 0) {
|
|
||||||
|
/* note, g_mkdir_with_parents won't detect an error if
|
||||||
|
* there's already such a dir, but with the wrong
|
||||||
|
* permissions; so we need to check */
|
||||||
|
if (rv != 0 || !mu_util_check_dir(fullpath, TRUE, TRUE)) {
|
||||||
g_set_error (err, 0, MU_ERROR_FILE_CANNOT_MKDIR,
|
g_set_error (err, 0, MU_ERROR_FILE_CANNOT_MKDIR,
|
||||||
"g_mkdir_with_parents failed: %s",
|
"creating dir failed for %s: %s",
|
||||||
|
fullpath,
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -860,6 +862,3 @@ mu_maildir_move_message (const char* oldpath, const char* targetmdir,
|
||||||
|
|
||||||
return newfullpath;
|
return newfullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
** under the terms of the GNU General Public License as published by the
|
** under the terms of the GNU General Public License as published by the
|
||||||
|
@ -30,19 +30,22 @@
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a new maildir. Note, if the function fails 'halfway', it
|
* create a new maildir. if parts of the maildir already exists, those
|
||||||
* will *not* try to remove the parts the were created. it *will*
|
* will simply be ignored. IOW, if you try to create the same maildir
|
||||||
* create any parent dirs that are not yet existant.
|
* twice, the second will simply be a no-op (without any errors).
|
||||||
|
* Note, if the function fails 'halfway', it will *not* try to remove
|
||||||
|
* the parts the were created. it *will* create any parent dirs that
|
||||||
|
* are not yet existent.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param path the path (missing components will be created, as in 'mkdir -p')
|
* @param path the path (missing components will be created, as in 'mkdir -p')
|
||||||
* @param mode the file mode (e.g., 0755)
|
* @param mode the file mode (e.g., 0755)
|
||||||
* @param noindex add a .noindex file to the maildir, so it will be excluded
|
* @param noindex add a .noindex file to the maildir, so it will be excluded
|
||||||
* from indexing by 'mu index'
|
* from indexing by 'mu index'
|
||||||
* @param err if function returns FALSE, err may contain extra
|
* @param err if function returns FALSE, receives error
|
||||||
* information. if err is NULL, does nothing
|
* information. err may be NULL.
|
||||||
*
|
*
|
||||||
* @return TRUE if creation succeeded, FALSE otherwise
|
* @return TRUE if creation succeeded (or already existed), FALSE otherwise
|
||||||
*/
|
*/
|
||||||
gboolean mu_maildir_mkdir (const char* path, mode_t mode, gboolean noindex,
|
gboolean mu_maildir_mkdir (const char* path, mode_t mode, gboolean noindex,
|
||||||
GError **err);
|
GError **err);
|
||||||
|
@ -60,7 +63,8 @@ gboolean mu_maildir_mkdir (const char* path, mode_t mode, gboolean noindex,
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
gboolean mu_maildir_link (const char* src, const char *targetpath, GError **err);
|
gboolean mu_maildir_link (const char* src, const char *targetpath,
|
||||||
|
GError **err);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MuMaildirWalkMsgCallback -- callback function for
|
* MuMaildirWalkMsgCallback -- callback function for
|
||||||
|
@ -72,7 +76,8 @@ gboolean mu_maildir_link (const char* src, const char *targetpath, GError **er
|
||||||
* file (see stat(3)), and a user_data pointer
|
* file (see stat(3)), and a user_data pointer
|
||||||
*/
|
*/
|
||||||
typedef MuError (*MuMaildirWalkMsgCallback)
|
typedef MuError (*MuMaildirWalkMsgCallback)
|
||||||
(const char* fullpath, const char* mdir, struct stat *statinfo, void *user_data);
|
(const char* fullpath, const char* mdir, struct stat *statinfo,
|
||||||
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MuPathWalkDirCallback -- callback function for mu_path_walk_maildir; see the
|
* MuPathWalkDirCallback -- callback function for mu_path_walk_maildir; see the
|
||||||
|
|
Loading…
Reference in New Issue