dovecot-2.2: Moved lib-fs/fs-test to "doveadm fs" command.
dovecot at dovecot.org
dovecot at dovecot.org
Sun Apr 7 19:50:43 EEST 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/d09aa718221f
changeset: 16229:d09aa718221f
user: Timo Sirainen <tss at iki.fi>
date: Sun Apr 07 19:50:29 2013 +0300
description:
Moved lib-fs/fs-test to "doveadm fs" command.
diffstat:
.hgignore | 1 -
src/doveadm/Makefile.am | 1 +
src/doveadm/doveadm-fs.c | 232 +++++++++++++++++++++++++++++++++++++++++
src/doveadm/doveadm-settings.c | 2 +
src/doveadm/doveadm-settings.h | 1 +
src/doveadm/doveadm.c | 1 +
src/doveadm/doveadm.h | 1 +
src/lib-fs/Makefile.am | 12 --
src/lib-fs/fs-test.c | 164 ----------------------------
9 files changed, 238 insertions(+), 177 deletions(-)
diffs (truncated from 504 to 300 lines):
diff -r 0b7cb5fdc7b5 -r d09aa718221f .hgignore
--- a/.hgignore Sun Apr 07 18:50:31 2013 +0300
+++ b/.hgignore Sun Apr 07 19:50:29 2013 +0300
@@ -77,7 +77,6 @@
src/ipc/ipc
src/lib/unicodemap.c
src/lib/UnicodeData.txt
-src/lib-fs/fs-test
src/lib-dict/dict-drivers-register.c
src/lib-sql/sql-drivers-register.c
src/lib-storage/register/mail-storage-register.c
diff -r 0b7cb5fdc7b5 -r d09aa718221f src/doveadm/Makefile.am
--- a/src/doveadm/Makefile.am Sun Apr 07 18:50:31 2013 +0300
+++ b/src/doveadm/Makefile.am Sun Apr 07 19:50:29 2013 +0300
@@ -89,6 +89,7 @@
doveadm-dump-log.c \
doveadm-dump-mailboxlog.c \
doveadm-dump-thread.c \
+ doveadm-fs.c \
doveadm-instance.c \
doveadm-kick.c \
doveadm-log.c \
diff -r 0b7cb5fdc7b5 -r d09aa718221f src/doveadm/doveadm-fs.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/doveadm/doveadm-fs.c Sun Apr 07 19:50:29 2013 +0300
@@ -0,0 +1,232 @@
+/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "istream.h"
+#include "ostream.h"
+#include "iostream-ssl.h"
+#include "fs-api.h"
+#include "doveadm.h"
+
+#include <stdio.h>
+
+static void fs_cmd_help(doveadm_command_t *cmd);
+
+static struct fs *
+cmd_fs_init(int *argc, char **argv[], int own_arg_count, doveadm_command_t *cmd)
+{
+ struct ssl_iostream_settings ssl_set;
+ struct fs_settings fs_set;
+ struct fs *fs;
+ const char *error;
+
+ if (*argc != 3 + own_arg_count)
+ fs_cmd_help(cmd);
+
+ memset(&ssl_set, 0, sizeof(ssl_set));
+ ssl_set.ca_dir = doveadm_settings->ssl_client_ca_dir;
+
+ memset(&fs_set, 0, sizeof(fs_set));
+ fs_set.ssl_client_set = &ssl_set;
+ fs_set.temp_dir = "/tmp";
+
+ if (fs_init((*argv)[1], (*argv)[2], &fs_set, &fs, &error) < 0)
+ i_fatal("fs_init() failed: %s", error);
+
+ *argc += 3;
+ *argv += 3;
+ return fs;
+}
+
+static void cmd_fs_get(int argc, char *argv[])
+{
+ struct fs *fs;
+ struct fs_file *file;
+ struct istream *input;
+ const unsigned char *data;
+ size_t size;
+ ssize_t ret;
+
+ fs = cmd_fs_init(&argc, &argv, 1, cmd_fs_get);
+
+ file = fs_file_init(fs, argv[0], FS_OPEN_MODE_READONLY);
+ input = fs_read_stream(file, IO_BLOCK_SIZE);
+ while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) {
+ fwrite(data, 1, size, stdout);
+ i_stream_skip(input, size);
+ }
+ i_assert(ret == -1);
+ if (input->stream_errno == ENOENT) {
+ i_error("%s doesn't exist", fs_file_path(file));
+ doveadm_exit_code = DOVEADM_EX_NOTFOUND;
+ } else if (input->stream_errno != 0) {
+ i_error("read(%s) failed: %m", fs_file_path(file));
+ doveadm_exit_code = EX_TEMPFAIL;
+ }
+ i_stream_unref(&input);
+ fs_file_deinit(&file);
+ fs_deinit(&fs);
+}
+
+static void cmd_fs_put(int argc, char *argv[])
+{
+ struct fs *fs;
+ const char *src_path, *dest_path;
+ struct fs_file *file;
+ struct istream *input;
+ struct ostream *output;
+ off_t ret;
+
+ fs = cmd_fs_init(&argc, &argv, 2, cmd_fs_put);
+ src_path = argv[0];
+ dest_path = argv[1];
+
+ file = fs_file_init(fs, dest_path, FS_OPEN_MODE_REPLACE);
+ output = fs_write_stream(file);
+ input = i_stream_create_file(src_path, IO_BLOCK_SIZE);
+ if ((ret = o_stream_send_istream(output, input)) < 0) {
+ if (output->stream_errno != 0)
+ i_error("write(%s) failed: %m", dest_path);
+ else
+ i_error("read(%s) failed: %m", src_path);
+ doveadm_exit_code = EX_TEMPFAIL;
+ }
+ i_stream_destroy(&input);
+ if (fs_write_stream_finish(file, &output) < 0) {
+ i_error("fs_write_stream_finish() failed: %s",
+ fs_file_last_error(file));
+ doveadm_exit_code = EX_TEMPFAIL;
+ }
+ fs_file_deinit(&file);
+ fs_deinit(&fs);
+}
+
+static void cmd_fs_copy(int argc, char *argv[])
+{
+ struct fs *fs;
+ struct fs_file *src_file, *dest_file;
+ const char *src_path, *dest_path;
+
+ fs = cmd_fs_init(&argc, &argv, 2, cmd_fs_copy);
+ src_path = argv[0];
+ dest_path = argv[1];
+
+ src_file = fs_file_init(fs, src_path, FS_OPEN_MODE_READONLY);
+ dest_file = fs_file_init(fs, dest_path, FS_OPEN_MODE_REPLACE);
+ if (fs_copy(src_file, dest_file) == 0) ;
+ else if (errno == ENOENT) {
+ i_error("%s doesn't exist", src_path);
+ doveadm_exit_code = DOVEADM_EX_NOTFOUND;
+ } else {
+ i_error("fs_copy(%s, %s) failed: %s",
+ src_path, dest_path, fs_last_error(fs));
+ doveadm_exit_code = EX_TEMPFAIL;
+ }
+ fs_file_deinit(&src_file);
+ fs_file_deinit(&dest_file);
+ fs_deinit(&fs);
+}
+
+static void cmd_fs_stat(int argc, char *argv[])
+{
+ struct fs *fs;
+ struct fs_file *file;
+ struct stat st;
+
+ fs = cmd_fs_init(&argc, &argv, 1, cmd_fs_stat);
+
+ file = fs_file_init(fs, argv[0], FS_OPEN_MODE_READONLY);
+ if (fs_stat(file, &st) == 0) {
+ printf("%s size=%lld\n", fs_file_path(file),
+ (long long)st.st_size);
+ } else if (errno == ENOENT) {
+ i_error("%s doesn't exist", fs_file_path(file));
+ doveadm_exit_code = DOVEADM_EX_NOTFOUND;
+ } else {
+ i_error("fs_stat(%s) failed: %s",
+ fs_file_path(file), fs_file_last_error(file));
+ doveadm_exit_code = EX_TEMPFAIL;
+ }
+ fs_file_deinit(&file);
+ fs_deinit(&fs);
+}
+
+static void cmd_fs_delete(int argc, char *argv[])
+{
+ struct fs *fs;
+ struct fs_file *file;
+
+ fs = cmd_fs_init(&argc, &argv, 1, cmd_fs_delete);
+
+ file = fs_file_init(fs, argv[0], FS_OPEN_MODE_READONLY);
+ if (fs_delete(file) == 0)
+ ;
+ else if (errno == ENOENT) {
+ i_error("%s doesn't exist", fs_file_path(file));
+ doveadm_exit_code = DOVEADM_EX_NOTFOUND;
+ } else {
+ i_error("fs_delete(%s) failed: %s",
+ fs_file_path(file), fs_file_last_error(file));
+ doveadm_exit_code = EX_TEMPFAIL;
+ }
+ fs_file_deinit(&file);
+ fs_deinit(&fs);
+}
+
+static void cmd_fs_iter_full(int argc, char *argv[], enum fs_iter_flags flags,
+ doveadm_command_t *cmd)
+{
+ struct fs *fs;
+ struct fs_iter *iter;
+ const char *fname;
+
+ fs = cmd_fs_init(&argc, &argv, 1, cmd);
+
+ iter = fs_iter_init(fs, argv[0], flags);
+ while ((fname = fs_iter_next(iter)) != NULL)
+ printf("%s\n", fname);
+ if (fs_iter_deinit(&iter) < 0) {
+ i_error("fs_iter_deinit(%s) failed: %s",
+ argv[0], fs_last_error(fs));
+ doveadm_exit_code = EX_TEMPFAIL;
+ }
+ fs_deinit(&fs);
+}
+
+static void cmd_fs_iter(int argc, char *argv[])
+{
+ cmd_fs_iter_full(argc, argv, 0, cmd_fs_iter);
+}
+
+static void cmd_fs_iter_dirs(int argc, char *argv[])
+{
+ cmd_fs_iter_full(argc, argv, FS_ITER_FLAG_DIRS, cmd_fs_iter_dirs);
+}
+
+struct doveadm_cmd doveadm_cmd_fs[] = {
+ { cmd_fs_get, "fs get", "<fs-driver> <fs-args> <path>" },
+ { cmd_fs_put, "fs put", "<fs-driver> <fs-args> <input path> <path>" },
+ { cmd_fs_copy, "fs copy", "<fs-driver> <fs-args> <source path> <dest path>" },
+ { cmd_fs_stat, "fs stat", "<fs-driver> <fs-args> <path>" },
+ { cmd_fs_delete, "fs delete", "<fs-driver> <fs-args> <path>" },
+ { cmd_fs_iter, "fs iter", "<fs-driver> <fs-args> <path>" },
+ { cmd_fs_iter_dirs, "fs iter-dirs", "<fs-driver> <fs-args> <path>" },
+};
+
+static void fs_cmd_help(doveadm_command_t *cmd)
+{
+ unsigned int i;
+
+ for (i = 0; i < N_ELEMENTS(doveadm_cmd_fs); i++) {
+ if (doveadm_cmd_fs[i].cmd == cmd)
+ help(&doveadm_cmd_fs[i]);
+ }
+ i_unreached();
+}
+
+void doveadm_register_fs_commands(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < N_ELEMENTS(doveadm_cmd_fs); i++)
+ doveadm_register_cmd(&doveadm_cmd_fs[i]);
+}
diff -r 0b7cb5fdc7b5 -r d09aa718221f src/doveadm/doveadm-settings.c
--- a/src/doveadm/doveadm-settings.c Sun Apr 07 18:50:31 2013 +0300
+++ b/src/doveadm/doveadm-settings.c Sun Apr 07 19:50:29 2013 +0300
@@ -64,6 +64,7 @@
DEF(SET_STR, doveadm_allowed_commands),
DEF(SET_STR, dsync_alt_char),
DEF(SET_STR, dsync_remote_cmd),
+ DEF(SET_STR, ssl_client_ca_dir),
{ SET_STRLIST, "plugin", offsetof(struct doveadm_settings, plugin_envs), NULL },
@@ -82,6 +83,7 @@
.doveadm_allowed_commands = "",
.dsync_alt_char = "_",
.dsync_remote_cmd = "ssh -l%{login} %{host} doveadm dsync-server -u%u -U",
+ .ssl_client_ca_dir = "",
.plugin_envs = ARRAY_INIT
};
diff -r 0b7cb5fdc7b5 -r d09aa718221f src/doveadm/doveadm-settings.h
--- a/src/doveadm/doveadm-settings.h Sun Apr 07 18:50:31 2013 +0300
+++ b/src/doveadm/doveadm-settings.h Sun Apr 07 19:50:29 2013 +0300
@@ -13,6 +13,7 @@
const char *doveadm_allowed_commands;
const char *dsync_alt_char;
const char *dsync_remote_cmd;
+ const char *ssl_client_ca_dir;
ARRAY(const char *) plugin_envs;
};
diff -r 0b7cb5fdc7b5 -r d09aa718221f src/doveadm/doveadm.c
--- a/src/doveadm/doveadm.c Sun Apr 07 18:50:31 2013 +0300
+++ b/src/doveadm/doveadm.c Sun Apr 07 19:50:29 2013 +0300
@@ -368,6 +368,7 @@
doveadm_register_proxy_commands();
doveadm_register_log_commands();
doveadm_register_replicator_commands();
+ doveadm_register_fs_commands();
doveadm_dump_init();
doveadm_mail_init();
doveadm_load_modules();
diff -r 0b7cb5fdc7b5 -r d09aa718221f src/doveadm/doveadm.h
More information about the dovecot-cvs
mailing list