/* 'remove' removes the message with either docid: or msgid:, sends a * (:remove ...) message when it succeeds */ static MuError cmd_remove (ServerContext *ctx, GSList *args, GError **err) { unsigned docid; const char *path; docid = determine_docid (ctx->query, args, err); if (docid == MU_STORE_INVALID_DOCID) { print_and_clear_g_error (err); return MU_OK; } path = get_path_from_docid (ctx->store, docid, err); if (!path) { print_and_clear_g_error (err); return MU_OK; } if (unlink (path) != 0) { mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_UNLINK, "%s", strerror (errno)); print_and_clear_g_error (err); return MU_OK; } if (!mu_store_remove_path (ctx->store, path)) { print_error (MU_ERROR_XAPIAN_REMOVE_FAILED, "failed to remove from database"); return MU_OK; } print_expr ("(:remove %u)", docid); return MU_OK; }
static MuError foreach_doc_cb (const char* path, CleanupData *cudata) { if (access (path, R_OK) != 0) { if (errno != EACCES) g_debug ("cannot access %s: %s", path, strerror(errno)); if (!mu_store_remove_path (cudata->_store, path)) return MU_ERROR; /* something went wrong... bail out */ if (cudata->_stats) ++cudata->_stats->_cleaned_up; } if (cudata->_stats) ++cudata->_stats->_processed; if (!cudata->_cb) return MU_OK; return cudata->_cb (cudata->_stats, cudata->_user_data); }
MuError mu_cmd_remove (MuStore *store, MuConfig *opts, GError **err) { gboolean allok; int i; g_return_val_if_fail (opts, MU_ERROR_INTERNAL); g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_REMOVE, MU_ERROR_INTERNAL); /* note: params[0] will be 'add' */ if (!opts->params[0] || !opts->params[1]) { g_warning ("usage: mu remove <file> [<files>]"); g_set_error (err, 0, MU_ERROR_IN_PARAMETERS, "missing source and/or target"); return MU_ERROR_IN_PARAMETERS; } for (i = 1, allok = TRUE; opts->params[i]; ++i) { const char* src; src = opts->params[i]; if (!check_file_okay (src, FALSE) || !mu_store_remove_path (store, src)) { allok = FALSE; MU_WRITE_LOG ("failed to remove %s", src); } } if (!allok) { g_set_error (err, 0, MU_ERROR_XAPIAN_STORE_FAILED, "remove failed for some message(s)"); return MU_ERROR_XAPIAN_REMOVE_FAILED; } return MU_OK; }