doveadm-fs.c (dovecot-2.3.16) | : | doveadm-fs.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 19 | skipping to change at line 19 | |||
#include "istream.h" | #include "istream.h" | |||
#include "ostream.h" | #include "ostream.h" | |||
#include "iostream-ssl.h" | #include "iostream-ssl.h" | |||
#include "fs-api.h" | #include "fs-api.h" | |||
#include "doveadm.h" | #include "doveadm.h" | |||
#include "doveadm-print.h" | #include "doveadm-print.h" | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <unistd.h> | #include <unistd.h> | |||
static void fs_cmd_help(doveadm_command_t *cmd); | static void fs_cmd_help(struct doveadm_cmd_context *cctx) ATTR_NORETURN; | |||
static void cmd_fs_delete(int argc, char *argv[]); | static void cmd_fs_delete(struct doveadm_cmd_context *cctx); | |||
static void cmd_fs_getopt(int *argc, char **argv[]) | ||||
{ | ||||
if (getopt(*argc, *argv, "") == '?') | ||||
i_fatal("fs_init: Add -- if you have - in arguments"); | ||||
*argc -= optind; | ||||
*argv += optind; | ||||
} | ||||
static struct fs * | static struct fs * | |||
cmd_fs_init(int *argc, char **argv[], int own_arg_count, doveadm_command_t *cmd) | cmd_fs_init(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
struct ssl_iostream_settings ssl_set; | struct ssl_iostream_settings ssl_set; | |||
struct fs_settings fs_set; | struct fs_settings fs_set; | |||
struct fs *fs; | struct fs *fs; | |||
const char *error; | const char *fs_driver, *fs_args, *error; | |||
if (own_arg_count > 0) { | if (!doveadm_cmd_param_str(cctx, "fs-driver", &fs_driver) || | |||
if (*argc != 2 + own_arg_count) | !doveadm_cmd_param_str(cctx, "fs-args", &fs_args)) | |||
fs_cmd_help(cmd); | fs_cmd_help(cctx); | |||
} else { | ||||
if (*argc <= 2) | ||||
fs_cmd_help(cmd); | ||||
} | ||||
doveadm_get_ssl_settings(&ssl_set, pool_datastack_create()); | doveadm_get_ssl_settings(&ssl_set, pool_datastack_create()); | |||
ssl_set.verbose = doveadm_debug; | ssl_set.verbose = doveadm_debug; | |||
i_zero(&fs_set); | i_zero(&fs_set); | |||
fs_set.ssl_client_set = &ssl_set; | fs_set.ssl_client_set = &ssl_set; | |||
fs_set.temp_dir = doveadm_settings->mail_temp_dir; | fs_set.temp_dir = doveadm_settings->mail_temp_dir; | |||
fs_set.base_dir = doveadm_settings->base_dir; | fs_set.base_dir = doveadm_settings->base_dir; | |||
fs_set.debug = doveadm_debug; | fs_set.debug = doveadm_debug; | |||
if (fs_init((*argv)[0], (*argv)[1], &fs_set, &fs, &error) < 0) | if (fs_init(fs_driver, fs_args, &fs_set, &fs, &error) < 0) | |||
i_fatal("fs_init() failed: %s", error); | i_fatal("fs_init() failed: %s", error); | |||
*argc += 2; | ||||
*argv += 2; | ||||
return fs; | return fs; | |||
} | } | |||
static void cmd_fs_get(int argc, char *argv[]) | static void cmd_fs_get(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
struct fs *fs; | struct fs *fs; | |||
struct fs_file *file; | struct fs_file *file; | |||
struct istream *input; | struct istream *input; | |||
const char *path; | ||||
const unsigned char *data; | const unsigned char *data; | |||
size_t size; | size_t size; | |||
ssize_t ret; | ssize_t ret; | |||
doveadm_print_init(DOVEADM_PRINT_TYPE_PAGER); | doveadm_print_init(DOVEADM_PRINT_TYPE_PAGER); | |||
doveadm_print_header("content", "content", DOVEADM_PRINT_HEADER_FLAG_HIDE _TITLE); | doveadm_print_header("content", "content", DOVEADM_PRINT_HEADER_FLAG_HIDE _TITLE); | |||
cmd_fs_getopt(&argc, &argv); | fs = cmd_fs_init(cctx); | |||
fs = cmd_fs_init(&argc, &argv, 1, cmd_fs_get); | if (!doveadm_cmd_param_str(cctx, "path", &path)) | |||
fs_cmd_help(cctx); | ||||
file = fs_file_init(fs, argv[0], FS_OPEN_MODE_READONLY); | file = fs_file_init(fs, path, FS_OPEN_MODE_READONLY); | |||
input = fs_read_stream(file, IO_BLOCK_SIZE); | input = fs_read_stream(file, IO_BLOCK_SIZE); | |||
while ((ret = i_stream_read_more(input, &data, &size)) > 0) { | while ((ret = i_stream_read_more(input, &data, &size)) > 0) { | |||
doveadm_print_stream(data, size); | doveadm_print_stream(data, size); | |||
i_stream_skip(input, size); | i_stream_skip(input, size); | |||
} | } | |||
doveadm_print_stream("", 0); | doveadm_print_stream("", 0); | |||
i_assert(ret == -1); | i_assert(ret == -1); | |||
if (input->stream_errno == ENOENT) { | if (input->stream_errno == ENOENT) { | |||
i_error("%s doesn't exist: %s", fs_file_path(file), | i_error("%s doesn't exist: %s", fs_file_path(file), | |||
i_stream_get_error(input)); | i_stream_get_error(input)); | |||
skipping to change at line 99 | skipping to change at line 86 | |||
} else if (input->stream_errno != 0) { | } else if (input->stream_errno != 0) { | |||
i_error("read(%s) failed: %s", fs_file_path(file), | i_error("read(%s) failed: %s", fs_file_path(file), | |||
i_stream_get_error(input)); | i_stream_get_error(input)); | |||
doveadm_exit_code = EX_TEMPFAIL; | doveadm_exit_code = EX_TEMPFAIL; | |||
} | } | |||
i_stream_unref(&input); | i_stream_unref(&input); | |||
fs_file_deinit(&file); | fs_file_deinit(&file); | |||
fs_deinit(&fs); | fs_deinit(&fs); | |||
} | } | |||
static void cmd_fs_put(int argc, char *argv[]) | static void cmd_fs_put(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
struct fs *fs; | struct fs *fs; | |||
enum fs_properties props; | enum fs_properties props; | |||
const char *src_path, *dest_path; | const char *hash_str, *src_path, *dest_path; | |||
struct fs_file *file; | struct fs_file *file; | |||
struct istream *input; | struct istream *input; | |||
struct ostream *output; | struct ostream *output; | |||
buffer_t *hash = NULL; | buffer_t *hash = NULL; | |||
int c; | ||||
while ((c = getopt(argc, argv, "h:")) > 0) { | fs = cmd_fs_init(cctx); | |||
switch (c) { | if (!doveadm_cmd_param_str(cctx, "input-path", &src_path) || | |||
case 'h': | !doveadm_cmd_param_str(cctx, "path", &dest_path)) | |||
hash = t_buffer_create(32); | fs_cmd_help(cctx); | |||
if (hex_to_binary(optarg, hash) < 0) | if (doveadm_cmd_param_str(cctx, "hash", &hash_str)) { | |||
i_fatal("Invalid -h parameter: Hash not in hex"); | hash = t_buffer_create(32); | |||
break; | if (hex_to_binary(optarg, hash) < 0) | |||
default: | i_fatal("Invalid -h parameter: Hash not in hex"); | |||
fs_cmd_help(cmd_fs_put); | ||||
} | ||||
} | } | |||
argc -= optind; argv += optind; | ||||
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); | file = fs_file_init(fs, dest_path, FS_OPEN_MODE_REPLACE); | |||
props = fs_get_properties(fs); | props = fs_get_properties(fs); | |||
if (hash == NULL) | if (hash == NULL) | |||
; | ; | |||
else if (hash->used == hash_method_md5.digest_size) { | else if (hash->used == hash_method_md5.digest_size) { | |||
if ((props & FS_PROPERTY_WRITE_HASH_MD5) == 0) | if ((props & FS_PROPERTY_WRITE_HASH_MD5) == 0) | |||
i_fatal("fs backend doesn't support MD5 hashes"); | i_fatal("fs backend doesn't support MD5 hashes"); | |||
fs_write_set_hash(file, | fs_write_set_hash(file, | |||
hash_method_lookup(hash_method_md5.name), hash->data); | hash_method_lookup(hash_method_md5.name), hash->data); | |||
skipping to change at line 156 | skipping to change at line 135 | |||
i_stream_destroy(&input); | i_stream_destroy(&input); | |||
if (fs_write_stream_finish(file, &output) < 0) { | if (fs_write_stream_finish(file, &output) < 0) { | |||
i_error("fs_write_stream_finish() failed: %s", | i_error("fs_write_stream_finish() failed: %s", | |||
fs_file_last_error(file)); | fs_file_last_error(file)); | |||
doveadm_exit_code = EX_TEMPFAIL; | doveadm_exit_code = EX_TEMPFAIL; | |||
} | } | |||
fs_file_deinit(&file); | fs_file_deinit(&file); | |||
fs_deinit(&fs); | fs_deinit(&fs); | |||
} | } | |||
static void cmd_fs_copy(int argc, char *argv[]) | static void cmd_fs_copy(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
struct fs *fs; | struct fs *fs; | |||
struct fs_file *src_file, *dest_file; | struct fs_file *src_file, *dest_file; | |||
const char *src_path, *dest_path; | const char *src_path, *dest_path; | |||
cmd_fs_getopt(&argc, &argv); | fs = cmd_fs_init(cctx); | |||
fs = cmd_fs_init(&argc, &argv, 2, cmd_fs_copy); | if (!doveadm_cmd_param_str(cctx, "source-path", &src_path) || | |||
src_path = argv[0]; | !doveadm_cmd_param_str(cctx, "destination-path", &dest_path)) | |||
dest_path = argv[1]; | fs_cmd_help(cctx); | |||
src_file = fs_file_init(fs, src_path, FS_OPEN_MODE_READONLY); | src_file = fs_file_init(fs, src_path, FS_OPEN_MODE_READONLY); | |||
dest_file = fs_file_init(fs, dest_path, FS_OPEN_MODE_REPLACE); | dest_file = fs_file_init(fs, dest_path, FS_OPEN_MODE_REPLACE); | |||
if (fs_copy(src_file, dest_file) == 0) ; | if (fs_copy(src_file, dest_file) == 0) ; | |||
else if (errno == ENOENT) { | else if (errno == ENOENT) { | |||
i_error("%s doesn't exist: %s", src_path, | i_error("%s doesn't exist: %s", src_path, | |||
fs_file_last_error(dest_file)); | fs_file_last_error(dest_file)); | |||
doveadm_exit_code = DOVEADM_EX_NOTFOUND; | doveadm_exit_code = DOVEADM_EX_NOTFOUND; | |||
} else { | } else { | |||
i_error("fs_copy(%s, %s) failed: %s", | i_error("fs_copy(%s, %s) failed: %s", | |||
src_path, dest_path, fs_file_last_error(dest_file)); | src_path, dest_path, fs_file_last_error(dest_file)); | |||
doveadm_exit_code = EX_TEMPFAIL; | doveadm_exit_code = EX_TEMPFAIL; | |||
} | } | |||
fs_file_deinit(&src_file); | fs_file_deinit(&src_file); | |||
fs_file_deinit(&dest_file); | fs_file_deinit(&dest_file); | |||
fs_deinit(&fs); | fs_deinit(&fs); | |||
} | } | |||
static void cmd_fs_stat(int argc, char *argv[]) | static void cmd_fs_stat(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
struct fs *fs; | struct fs *fs; | |||
struct fs_file *file; | struct fs_file *file; | |||
struct stat st; | struct stat st; | |||
const char *path; | ||||
cmd_fs_getopt(&argc, &argv); | fs = cmd_fs_init(cctx); | |||
fs = cmd_fs_init(&argc, &argv, 1, cmd_fs_stat); | if (!doveadm_cmd_param_str(cctx, "path", &path)) | |||
fs_cmd_help(cctx); | ||||
file = fs_file_init(fs, argv[0], FS_OPEN_MODE_READONLY); | file = fs_file_init(fs, path, FS_OPEN_MODE_READONLY); | |||
doveadm_print_init(DOVEADM_PRINT_TYPE_FORMATTED); | doveadm_print_init(DOVEADM_PRINT_TYPE_FORMATTED); | |||
doveadm_print_formatted_set_format("%{path} size=%{size}"); | doveadm_print_formatted_set_format("%{path} size=%{size}"); | |||
doveadm_print_header_simple("path"); | doveadm_print_header_simple("path"); | |||
doveadm_print_header("size", "size", DOVEADM_PRINT_HEADER_FLAG_NUMBER); | doveadm_print_header("size", "size", DOVEADM_PRINT_HEADER_FLAG_NUMBER); | |||
if (fs_stat(file, &st) == 0) { | if (fs_stat(file, &st) == 0) { | |||
doveadm_print(fs_file_path(file)); | doveadm_print(fs_file_path(file)); | |||
doveadm_print(dec2str(st.st_size)); | doveadm_print(dec2str(st.st_size)); | |||
} else if (errno == ENOENT) { | } else if (errno == ENOENT) { | |||
skipping to change at line 216 | skipping to change at line 197 | |||
doveadm_exit_code = DOVEADM_EX_NOTFOUND; | doveadm_exit_code = DOVEADM_EX_NOTFOUND; | |||
} else { | } else { | |||
i_error("fs_stat(%s) failed: %s", | i_error("fs_stat(%s) failed: %s", | |||
fs_file_path(file), fs_file_last_error(file)); | fs_file_path(file), fs_file_last_error(file)); | |||
doveadm_exit_code = EX_TEMPFAIL; | doveadm_exit_code = EX_TEMPFAIL; | |||
} | } | |||
fs_file_deinit(&file); | fs_file_deinit(&file); | |||
fs_deinit(&fs); | fs_deinit(&fs); | |||
} | } | |||
static void cmd_fs_metadata(int argc, char *argv[]) | static void cmd_fs_metadata(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
struct fs *fs; | struct fs *fs; | |||
struct fs_file *file; | struct fs_file *file; | |||
const struct fs_metadata *m; | const struct fs_metadata *m; | |||
const ARRAY_TYPE(fs_metadata) *metadata; | const ARRAY_TYPE(fs_metadata) *metadata; | |||
const char *path; | ||||
cmd_fs_getopt(&argc, &argv); | fs = cmd_fs_init(cctx); | |||
fs = cmd_fs_init(&argc, &argv, 1, cmd_fs_metadata); | if (!doveadm_cmd_param_str(cctx, "path", &path)) | |||
fs_cmd_help(cctx); | ||||
file = fs_file_init(fs, argv[0], FS_OPEN_MODE_READONLY); | file = fs_file_init(fs, path, FS_OPEN_MODE_READONLY); | |||
doveadm_print_init(DOVEADM_PRINT_TYPE_FORMATTED); | doveadm_print_init(DOVEADM_PRINT_TYPE_FORMATTED); | |||
doveadm_print_formatted_set_format("%{key}=%{value}\n"); | doveadm_print_formatted_set_format("%{key}=%{value}\n"); | |||
doveadm_print_header_simple("key"); | doveadm_print_header_simple("key"); | |||
doveadm_print_header_simple("value"); | doveadm_print_header_simple("value"); | |||
if (fs_get_metadata(file, &metadata) == 0) { | if (fs_get_metadata(file, &metadata) == 0) { | |||
array_foreach(metadata, m) { | array_foreach(metadata, m) { | |||
doveadm_print(m->key); | doveadm_print(m->key); | |||
doveadm_print(m->value); | doveadm_print(m->value); | |||
skipping to change at line 416 | skipping to change at line 399 | |||
if (fs_delete(file) < 0) { | if (fs_delete(file) < 0) { | |||
i_error("fs_delete(%s) failed: %s", | i_error("fs_delete(%s) failed: %s", | |||
fs_file_path(file), fs_file_last_error(file)); | fs_file_path(file), fs_file_last_error(file)); | |||
doveadm_exit_code = EX_TEMPFAIL; | doveadm_exit_code = EX_TEMPFAIL; | |||
} | } | |||
fs_file_deinit(&file); | fs_file_deinit(&file); | |||
} | } | |||
} | } | |||
static void | static void | |||
cmd_fs_delete_recursive(int argc, char *argv[], unsigned int async_count) | cmd_fs_delete_recursive(struct doveadm_cmd_context *cctx, | |||
unsigned int async_count) | ||||
{ | { | |||
struct fs *fs; | struct fs *fs; | |||
const char *const *paths; | ||||
unsigned int i; | unsigned int i; | |||
fs = cmd_fs_init(&argc, &argv, 0, cmd_fs_delete); | fs = cmd_fs_init(cctx); | |||
for (i = 0; argv[i] != NULL; i++) | if (!doveadm_cmd_param_array(cctx, "path", &paths)) | |||
cmd_fs_delete_recursive_path(fs, argv[i], async_count); | fs_cmd_help(cctx); | |||
for (i = 0; paths[i] != NULL; i++) | ||||
cmd_fs_delete_recursive_path(fs, paths[i], async_count); | ||||
fs_deinit(&fs); | fs_deinit(&fs); | |||
} | } | |||
static void cmd_fs_delete_paths(int argc, char *argv[], | static void cmd_fs_delete_paths(struct doveadm_cmd_context *cctx, | |||
unsigned int async_count) | unsigned int async_count) | |||
{ | { | |||
struct fs *fs; | struct fs *fs; | |||
struct fs_delete_ctx ctx; | struct fs_delete_ctx ctx; | |||
const char *const *paths; | ||||
unsigned int i; | unsigned int i; | |||
int ret; | int ret; | |||
fs = cmd_fs_init(&argc, &argv, 0, cmd_fs_delete); | fs = cmd_fs_init(cctx); | |||
if (!doveadm_cmd_param_array(cctx, "path", &paths)) | ||||
fs_cmd_help(cctx); | ||||
i_zero(&ctx); | i_zero(&ctx); | |||
ctx.fs = fs; | ctx.fs = fs; | |||
ctx.path_prefix = ""; | ctx.path_prefix = ""; | |||
ctx.files_count = I_MAX(async_count, 1); | ctx.files_count = I_MAX(async_count, 1); | |||
ctx.files = t_new(struct fs_file *, ctx.files_count); | ctx.files = t_new(struct fs_file *, ctx.files_count); | |||
for (i = 0; argv[i] != NULL; i++) { | for (i = 0; paths[i] != NULL; i++) { | |||
T_BEGIN { | T_BEGIN { | |||
ret = doveadm_fs_delete_async_fname(&ctx, argv[i]); | ret = doveadm_fs_delete_async_fname(&ctx, paths[i]); | |||
} T_END; | } T_END; | |||
if (ret < 0) | if (ret < 0) | |||
break; | break; | |||
} | } | |||
doveadm_fs_delete_async_finish(&ctx); | doveadm_fs_delete_async_finish(&ctx); | |||
fs_deinit(&fs); | fs_deinit(&fs); | |||
} | } | |||
static void cmd_fs_delete(int argc, char *argv[]) | static void cmd_fs_delete(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
bool recursive = FALSE; | bool recursive = FALSE; | |||
unsigned int async_count = 0; | int64_t async_count = 0; | |||
int c; | ||||
while ((c = getopt(argc, argv, "Rn:")) > 0) { | (void)doveadm_cmd_param_bool(cctx, "recursive", &recursive); | |||
switch (c) { | (void)doveadm_cmd_param_int64(cctx, "max-parallel", &async_count); | |||
case 'R': | ||||
recursive = TRUE; | ||||
break; | ||||
case 'n': | ||||
if (str_to_uint(optarg, &async_count) < 0) | ||||
i_fatal("Invalid -n parameter: %s", optarg); | ||||
break; | ||||
default: | ||||
fs_cmd_help(cmd_fs_delete); | ||||
} | ||||
} | ||||
argc -= optind; argv += optind; | ||||
if (recursive) | if (recursive) | |||
cmd_fs_delete_recursive(argc, argv, async_count); | cmd_fs_delete_recursive(cctx, async_count); | |||
else | else | |||
cmd_fs_delete_paths(argc, argv, async_count); | cmd_fs_delete_paths(cctx, async_count); | |||
} | } | |||
static void cmd_fs_iter_full(int argc, char *argv[], enum fs_iter_flags flags, | static void cmd_fs_iter_full(struct doveadm_cmd_context *cctx, | |||
doveadm_command_t *cmd) | enum fs_iter_flags flags) | |||
{ | { | |||
struct fs *fs; | struct fs *fs; | |||
struct fs_iter *iter; | struct fs_iter *iter; | |||
const char *fname, *error; | const char *path, *fname, *error; | |||
int c; | bool b; | |||
while ((c = getopt(argc, argv, "CO")) > 0) { | if (doveadm_cmd_param_bool(cctx, "no-cache", &b) && b) | |||
switch (c) { | flags |= FS_ITER_FLAG_NOCACHE; | |||
case 'C': | if (doveadm_cmd_param_bool(cctx, "object-ids", &b) && b) | |||
flags |= FS_ITER_FLAG_NOCACHE; | flags |= FS_ITER_FLAG_OBJECTIDS; | |||
break; | ||||
case 'O': | fs = cmd_fs_init(cctx); | |||
flags |= FS_ITER_FLAG_OBJECTIDS; | if (!doveadm_cmd_param_str(cctx, "path", &path)) | |||
break; | fs_cmd_help(cctx); | |||
default: | ||||
fs_cmd_help(cmd); | ||||
} | ||||
} | ||||
argc -= optind; argv += optind; | ||||
fs = cmd_fs_init(&argc, &argv, 1, cmd); | ||||
doveadm_print_init(DOVEADM_PRINT_TYPE_FORMATTED); | doveadm_print_init(DOVEADM_PRINT_TYPE_FORMATTED); | |||
doveadm_print_formatted_set_format("%{path}\n"); | doveadm_print_formatted_set_format("%{path}\n"); | |||
doveadm_print_header_simple("path"); | doveadm_print_header_simple("path"); | |||
iter = fs_iter_init(fs, argv[0], flags); | iter = fs_iter_init(fs, path, flags); | |||
while ((fname = fs_iter_next(iter)) != NULL) { | while ((fname = fs_iter_next(iter)) != NULL) { | |||
doveadm_print(fname); | doveadm_print(fname); | |||
} | } | |||
if (fs_iter_deinit(&iter, &error) < 0) { | if (fs_iter_deinit(&iter, &error) < 0) { | |||
i_error("fs_iter_deinit(%s) failed: %s", | i_error("fs_iter_deinit(%s) failed: %s", path, error); | |||
argv[0], error); | ||||
doveadm_exit_code = EX_TEMPFAIL; | doveadm_exit_code = EX_TEMPFAIL; | |||
} | } | |||
fs_deinit(&fs); | fs_deinit(&fs); | |||
} | } | |||
static void cmd_fs_iter(int argc, char *argv[]) | static void cmd_fs_iter(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
cmd_fs_iter_full(argc, argv, 0, cmd_fs_iter); | cmd_fs_iter_full(cctx, 0); | |||
} | } | |||
static void cmd_fs_iter_dirs(int argc, char *argv[]) | static void cmd_fs_iter_dirs(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
cmd_fs_iter_full(argc, argv, FS_ITER_FLAG_DIRS, cmd_fs_iter_dirs); | cmd_fs_iter_full(cctx, FS_ITER_FLAG_DIRS); | |||
} | } | |||
struct doveadm_cmd_ver2 doveadm_cmd_fs[] = { | struct doveadm_cmd_ver2 doveadm_cmd_fs[] = { | |||
{ | { | |||
.name = "fs get", | .name = "fs get", | |||
.old_cmd = cmd_fs_get, | .cmd = cmd_fs_get, | |||
.usage = "<fs-driver> <fs-args> <path>", | .usage = "<fs-driver> <fs-args> <path>", | |||
DOVEADM_CMD_PARAMS_START | DOVEADM_CMD_PARAMS_START | |||
DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAMS_END | DOVEADM_CMD_PARAMS_END | |||
}, | }, | |||
{ | { | |||
.name = "fs put", | .name = "fs put", | |||
.old_cmd = cmd_fs_put, | .cmd = cmd_fs_put, | |||
.usage = "[-h <hash>] <fs-driver> <fs-args> <input path> <path>", | .usage = "[-h <hash>] <fs-driver> <fs-args> <input path> <path>", | |||
DOVEADM_CMD_PARAMS_START | DOVEADM_CMD_PARAMS_START | |||
DOVEADM_CMD_PARAM('h', "hash", CMD_PARAM_STR, 0) | DOVEADM_CMD_PARAM('h', "hash", CMD_PARAM_STR, 0) | |||
DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "input-path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "input-path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAMS_END | DOVEADM_CMD_PARAMS_END | |||
}, | }, | |||
{ | { | |||
.name = "fs copy", | .name = "fs copy", | |||
.old_cmd = cmd_fs_copy, | .cmd = cmd_fs_copy, | |||
.usage = "<fs-driver> <fs-args> <source path> <dest path>", | .usage = "<fs-driver> <fs-args> <source path> <dest path>", | |||
DOVEADM_CMD_PARAMS_START | DOVEADM_CMD_PARAMS_START | |||
DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "source-path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "source-path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "destination-path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITI ONAL) | DOVEADM_CMD_PARAM('\0', "destination-path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITI ONAL) | |||
DOVEADM_CMD_PARAMS_END | DOVEADM_CMD_PARAMS_END | |||
}, | }, | |||
{ | { | |||
.name = "fs stat", | .name = "fs stat", | |||
.old_cmd = cmd_fs_stat, | .cmd = cmd_fs_stat, | |||
.usage = "<fs-driver> <fs-args> <path>", | .usage = "<fs-driver> <fs-args> <path>", | |||
DOVEADM_CMD_PARAMS_START | DOVEADM_CMD_PARAMS_START | |||
DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAMS_END | DOVEADM_CMD_PARAMS_END | |||
}, | }, | |||
{ | { | |||
.name = "fs metadata", | .name = "fs metadata", | |||
.old_cmd = cmd_fs_metadata, | .cmd = cmd_fs_metadata, | |||
.usage = "<fs-driver> <fs-args> <path>", | .usage = "<fs-driver> <fs-args> <path>", | |||
DOVEADM_CMD_PARAMS_START | DOVEADM_CMD_PARAMS_START | |||
DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAMS_END | DOVEADM_CMD_PARAMS_END | |||
}, | }, | |||
{ | { | |||
.name = "fs delete", | .name = "fs delete", | |||
.old_cmd = cmd_fs_delete, | .cmd = cmd_fs_delete, | |||
.usage = "[-R] [-n <count>] <fs-driver> <fs-args> <path> [<path> ...]", | .usage = "[-R] [-n <count>] <fs-driver> <fs-args> <path> [<path> ...]", | |||
DOVEADM_CMD_PARAMS_START | DOVEADM_CMD_PARAMS_START | |||
DOVEADM_CMD_PARAM('R', "recursive", CMD_PARAM_BOOL, 0) | DOVEADM_CMD_PARAM('R', "recursive", CMD_PARAM_BOOL, 0) | |||
DOVEADM_CMD_PARAM('n', "max-parallel", CMD_PARAM_INT64, 0) | DOVEADM_CMD_PARAM('n', "max-parallel", CMD_PARAM_INT64, 0) | |||
DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAMS_END | DOVEADM_CMD_PARAMS_END | |||
}, | }, | |||
{ | { | |||
.name = "fs iter", | .name = "fs iter", | |||
.old_cmd = cmd_fs_iter, | .cmd = cmd_fs_iter, | |||
.usage = "[--no-cache] [--object-ids] <fs-driver> <fs-args> <path>", | .usage = "[--no-cache] [--object-ids] <fs-driver> <fs-args> <path>", | |||
DOVEADM_CMD_PARAMS_START | DOVEADM_CMD_PARAMS_START | |||
DOVEADM_CMD_PARAM('C', "no-cache", CMD_PARAM_BOOL, 0) | DOVEADM_CMD_PARAM('C', "no-cache", CMD_PARAM_BOOL, 0) | |||
DOVEADM_CMD_PARAM('O', "object-ids", CMD_PARAM_BOOL, 0) | DOVEADM_CMD_PARAM('O', "object-ids", CMD_PARAM_BOOL, 0) | |||
DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAMS_END | DOVEADM_CMD_PARAMS_END | |||
}, | }, | |||
{ | { | |||
.name = "fs iter-dirs", | .name = "fs iter-dirs", | |||
.old_cmd = cmd_fs_iter_dirs, | .cmd = cmd_fs_iter_dirs, | |||
.usage = "<fs-driver> <fs-args> <path>", | .usage = "<fs-driver> <fs-args> <path>", | |||
DOVEADM_CMD_PARAMS_START | DOVEADM_CMD_PARAMS_START | |||
DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-driver", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "fs-args", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | |||
DOVEADM_CMD_PARAMS_END | DOVEADM_CMD_PARAMS_END | |||
} | } | |||
}; | }; | |||
static void fs_cmd_help(doveadm_command_t *cmd) | static void fs_cmd_help(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
unsigned int i; | unsigned int i; | |||
for (i = 0; i < N_ELEMENTS(doveadm_cmd_fs); i++) { | for (i = 0; i < N_ELEMENTS(doveadm_cmd_fs); i++) { | |||
if (doveadm_cmd_fs[i].old_cmd == cmd) | if (doveadm_cmd_fs[i].cmd == cctx->cmd->cmd) | |||
help_ver2(&doveadm_cmd_fs[i]); | help_ver2(&doveadm_cmd_fs[i]); | |||
} | } | |||
i_unreached(); | i_unreached(); | |||
} | } | |||
void doveadm_register_fs_commands(void) | void doveadm_register_fs_commands(void) | |||
{ | { | |||
unsigned int i; | unsigned int i; | |||
for (i = 0; i < N_ELEMENTS(doveadm_cmd_fs); i++) | for (i = 0; i < N_ELEMENTS(doveadm_cmd_fs); i++) | |||
End of changes. 57 change blocks. | ||||
121 lines changed or deleted | 91 lines changed or added |