* mu-maildir: use warnings instead of GErrors
This commit is contained in:
@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_create_maildir (const char *path, int mode, GError **err)
|
_create_maildir (const char *path, int mode)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const gchar* subdirs[] = {"new", "cur", "tmp"};
|
const gchar* subdirs[] = {"new", "cur", "tmp"};
|
||||||
@ -43,7 +43,7 @@ _create_maildir (const char *path, int mode, GError **err)
|
|||||||
if (access (path, F_OK) == 0)
|
if (access (path, F_OK) == 0)
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
g_set_error (err, 0, 0, "%s", strerror (errno));
|
g_warning ("%s", strerror (errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,8 +59,7 @@ _create_maildir (const char *path, int mode, GError **err)
|
|||||||
g_free (fullpath);
|
g_free (fullpath);
|
||||||
|
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
g_set_error (err, 0, 0, "%s",
|
g_warning ("%s", strerror (errno));
|
||||||
strerror (errno));
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +68,7 @@ _create_maildir (const char *path, int mode, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_create_noindex (const char *path, GError **err)
|
_create_noindex (const char *path)
|
||||||
{
|
{
|
||||||
/* create a noindex file if requested */
|
/* create a noindex file if requested */
|
||||||
int fd;
|
int fd;
|
||||||
@ -80,7 +79,7 @@ _create_noindex (const char *path, GError **err)
|
|||||||
fd = creat (noindexpath, 0644);
|
fd = creat (noindexpath, 0644);
|
||||||
g_free (noindexpath);
|
g_free (noindexpath);
|
||||||
if (fd < 0 || close (fd) != 0) {
|
if (fd < 0 || close (fd) != 0) {
|
||||||
g_set_error (err, 0, 0, "%s", strerror (errno));
|
g_warning ("%s", strerror (errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,16 +88,15 @@ _create_noindex (const char *path, GError **err)
|
|||||||
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mu_maildir_mkmdir (const char* path, int mode,
|
mu_maildir_mkmdir (const char* path, int mode, gboolean noindex)
|
||||||
gboolean noindex, GError **err)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
g_return_val_if_fail (path, FALSE);
|
g_return_val_if_fail (path, FALSE);
|
||||||
|
|
||||||
if (!_create_maildir (path, mode, err))
|
if (!_create_maildir (path, mode))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (noindex && !_create_noindex (path, err))
|
if (noindex && !_create_noindex (path))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -107,7 +105,7 @@ mu_maildir_mkmdir (const char* path, int mode,
|
|||||||
/* determine whether the source message is in 'new' or in 'cur';
|
/* determine whether the source message is in 'new' or in 'cur';
|
||||||
* we ignore messages in 'tmp' for obvious reasons */
|
* we ignore messages in 'tmp' for obvious reasons */
|
||||||
static gboolean
|
static gboolean
|
||||||
_check_subdir (const char *src, gboolean *in_cur, GError **err)
|
_check_subdir (const char *src, gboolean *in_cur)
|
||||||
{
|
{
|
||||||
gchar *srcpath;
|
gchar *srcpath;
|
||||||
|
|
||||||
@ -118,8 +116,7 @@ _check_subdir (const char *src, gboolean *in_cur, GError **err)
|
|||||||
else if (g_str_has_suffix (srcpath, "cur"))
|
else if (g_str_has_suffix (srcpath, "cur"))
|
||||||
*in_cur = TRUE;
|
*in_cur = TRUE;
|
||||||
else {
|
else {
|
||||||
g_set_error (err, 0, 0, "%s",
|
g_warning ("%s", "Invalid source message");
|
||||||
"Invalid source message");
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
g_free (srcpath);
|
g_free (srcpath);
|
||||||
@ -128,14 +125,13 @@ _check_subdir (const char *src, gboolean *in_cur, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gchar*
|
static gchar*
|
||||||
_get_target_fullpath (const char* src, const gchar *targetpath,
|
_get_target_fullpath (const char* src, const gchar *targetpath)
|
||||||
GError **err)
|
|
||||||
{
|
{
|
||||||
gchar *targetfullpath;
|
gchar *targetfullpath;
|
||||||
gchar *srcfile;
|
gchar *srcfile;
|
||||||
gboolean in_cur;
|
gboolean in_cur;
|
||||||
|
|
||||||
if (!_check_subdir (src, &in_cur, err))
|
if (!_check_subdir (src, &in_cur))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
srcfile = g_path_get_basename (src);
|
srcfile = g_path_get_basename (src);
|
||||||
@ -155,8 +151,7 @@ _get_target_fullpath (const char* src, const gchar *targetpath,
|
|||||||
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mu_maildir_link (const char* src, const char *targetpath,
|
mu_maildir_link (const char* src, const char *targetpath)
|
||||||
GError **err)
|
|
||||||
{
|
{
|
||||||
gchar *targetfullpath;
|
gchar *targetfullpath;
|
||||||
int rv;
|
int rv;
|
||||||
@ -166,20 +161,19 @@ mu_maildir_link (const char* src, const char *targetpath,
|
|||||||
|
|
||||||
/* just a basic check */
|
/* just a basic check */
|
||||||
if (access (src, R_OK) != 0) {
|
if (access (src, R_OK) != 0) {
|
||||||
g_set_error (err, 0, 0, "Cannot read source message: %s",
|
g_warning ("Cannot read source message: %s",
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
targetfullpath = _get_target_fullpath (src, targetpath, err);
|
targetfullpath = _get_target_fullpath (src, targetpath);
|
||||||
if (!targetfullpath)
|
if (!targetfullpath)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
rv = symlink (src, targetfullpath);
|
rv = symlink (src, targetfullpath);
|
||||||
g_free (targetfullpath);
|
g_free (targetfullpath);
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
g_set_error (err, 0, 0, "Error creating link: %s",
|
g_warning ("Error creating link: %s", strerror (errno));
|
||||||
strerror (errno));
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,12 +34,10 @@
|
|||||||
* @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 a GError* to receive error info, or NULL
|
|
||||||
*
|
*
|
||||||
* @return TRUE if creation succeeded, FALSE otherwise
|
* @return TRUE if creation succeeded, FALSE otherwise
|
||||||
*/
|
*/
|
||||||
gboolean mu_maildir_mkmdir (const char* path, int mode,
|
gboolean mu_maildir_mkmdir (const char* path, int mode, gboolean noindex);
|
||||||
gboolean noindex, GError **err);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,14 +48,10 @@ gboolean mu_maildir_mkmdir (const char* path, int mode,
|
|||||||
* @param targetpath the path to the target maildir; ie., *not*
|
* @param targetpath the path to the target maildir; ie., *not*
|
||||||
* MyMaildir/cur, but just MyMaildir/. The function will figure out
|
* MyMaildir/cur, but just MyMaildir/. The function will figure out
|
||||||
* the correct subdir then. *
|
* the correct subdir then. *
|
||||||
* @param err a GError* to receive error info, or NULL
|
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
gboolean mu_maildir_link (const char* src, const char *targetpath,
|
gboolean mu_maildir_link (const char* src, const char *targetpath);
|
||||||
GError **err);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MuMaildirWalkMsgCallback -- callback function for mu_path_walk_maildir;
|
* MuMaildirWalkMsgCallback -- callback function for mu_path_walk_maildir;
|
||||||
|
|||||||
@ -177,16 +177,9 @@ _do_output_text (MuQueryXapian *xapian, MuConfigOptions* opts, gchar **params)
|
|||||||
static gboolean
|
static gboolean
|
||||||
_create_linkdir_if_nonexistant (const gchar* linkdir)
|
_create_linkdir_if_nonexistant (const gchar* linkdir)
|
||||||
{
|
{
|
||||||
GError *err;
|
if (access (linkdir, F_OK) != 0)
|
||||||
|
if (!mu_maildir_mkmdir (linkdir, 0700, TRUE))
|
||||||
if (access (linkdir, F_OK) != 0) {
|
|
||||||
err = NULL;
|
|
||||||
if (!mu_maildir_mkmdir (linkdir, 0700, TRUE, &err)) {
|
|
||||||
g_printerr ("error: %s", err->message);
|
|
||||||
g_error_free (err);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -216,16 +209,10 @@ _do_output_links (MuQueryXapian *xapian, MuConfigOptions* opts, gchar **params)
|
|||||||
const char *path;
|
const char *path;
|
||||||
path = mu_msg_xapian_get_field (row, pathfield);
|
path = mu_msg_xapian_get_field (row, pathfield);
|
||||||
if (path) {
|
if (path) {
|
||||||
GError *err = NULL;
|
retval = mu_maildir_link (path, opts->linksdir);
|
||||||
if (!mu_maildir_link (path, opts->linksdir, &err)) {
|
if (!retval)
|
||||||
if (err) {
|
break;
|
||||||
g_printerr ("error: %s", err->message);
|
|
||||||
g_error_free (err);
|
|
||||||
}
|
}
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mu_msg_xapian_next (row);
|
mu_msg_xapian_next (row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
src/mu.c
21
src/mu.c
@ -115,14 +115,8 @@ make_maildir (MuConfigOptions *opts)
|
|||||||
|
|
||||||
i = 1;
|
i = 1;
|
||||||
while (opts->params[i]) {
|
while (opts->params[i]) {
|
||||||
GError *err = NULL;
|
if (!mu_maildir_mkmdir (opts->params[i], 0755, FALSE))
|
||||||
if (!mu_maildir_mkmdir (opts->params[i], 0755, FALSE,
|
|
||||||
&err)) {
|
|
||||||
g_printerr ("error creating %s: %s\n",
|
|
||||||
opts->params[i], err->message);
|
|
||||||
g_error_free (err);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,8 +128,6 @@ make_maildir (MuConfigOptions *opts)
|
|||||||
static int
|
static int
|
||||||
make_symlink (MuConfigOptions *opts)
|
make_symlink (MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
GError *err;
|
|
||||||
|
|
||||||
if (!opts->params[0])
|
if (!opts->params[0])
|
||||||
return 1; /* shouldn't happen */
|
return 1; /* shouldn't happen */
|
||||||
|
|
||||||
@ -144,16 +136,7 @@ make_symlink (MuConfigOptions *opts)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = NULL;
|
return mu_maildir_link (opts->params[1], opts->params[2]) ? 0 : 1;
|
||||||
if (!mu_maildir_link (opts->params[1], opts->params[2], &err)) {
|
|
||||||
if (err) {
|
|
||||||
g_printerr ("error: %s\n", err->message);
|
|
||||||
g_error_free (err);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user