doveadm-sis.c (dovecot-2.3.16) | : | doveadm-sis.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 209 | skipping to change at line 209 | |||
return 0; | return 0; | |||
else if (ret < 0) | else if (ret < 0) | |||
return -1; | return -1; | |||
/* too many hard links or inode changed */ | /* too many hard links or inode changed */ | |||
} | } | |||
/* replace hashes link with this */ | /* replace hashes link with this */ | |||
return hardlink_replace(path, hashes_path, st.st_ino) < 0 ? -1 : 0; | return hardlink_replace(path, hashes_path, st.st_ino) < 0 ? -1 : 0; | |||
} | } | |||
static void cmd_sis_deduplicate(int argc, char *argv[]) | static void cmd_sis_deduplicate(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
const char *rootdir, *queuedir; | const char *rootdir, *queuedir; | |||
DIR *dir; | DIR *dir; | |||
struct dirent *d; | struct dirent *d; | |||
struct stat st, first_st; | struct stat st, first_st; | |||
string_t *path; | string_t *path; | |||
size_t dir_len; | size_t dir_len; | |||
int ret; | int ret; | |||
if (argc < 3) | if (!doveadm_cmd_param_str(cctx, "root-dir", &rootdir) || | |||
help(&doveadm_cmd_sis_deduplicate); | !doveadm_cmd_param_str(cctx, "queue-dir", &queuedir)) | |||
help_ver2(&doveadm_cmd_sis_deduplicate); | ||||
/* go through the filenames in the queue dir and see if | /* go through the filenames in the queue dir and see if | |||
we can deduplicate them. */ | we can deduplicate them. */ | |||
rootdir = argv[1]; | ||||
queuedir = argv[2]; | ||||
if (stat(rootdir, &st) < 0) | if (stat(rootdir, &st) < 0) | |||
i_fatal("stat(%s) failed: %m", rootdir); | i_fatal("stat(%s) failed: %m", rootdir); | |||
path = t_str_new(256); | path = t_str_new(256); | |||
str_append(path, queuedir); | str_append(path, queuedir); | |||
str_append_c(path, '/'); | str_append_c(path, '/'); | |||
dir_len = str_len(path); | dir_len = str_len(path); | |||
dir = opendir(queuedir); | dir = opendir(queuedir); | |||
if (dir == NULL) | if (dir == NULL) | |||
skipping to change at line 267 | skipping to change at line 265 | |||
T_BEGIN { | T_BEGIN { | |||
ret = sis_try_deduplicate(rootdir, d->d_name); | ret = sis_try_deduplicate(rootdir, d->d_name); | |||
} T_END; | } T_END; | |||
if (ret == 0) | if (ret == 0) | |||
i_unlink(str_c(path)); | i_unlink(str_c(path)); | |||
} | } | |||
if (closedir(dir) < 0) | if (closedir(dir) < 0) | |||
i_error("closedir(%s) failed: %m", queuedir); | i_error("closedir(%s) failed: %m", queuedir); | |||
} | } | |||
static void cmd_sis_find(int argc, char *argv[]) | static void cmd_sis_find(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
const char *rootdir, *path, *hash; | const char *rootdir, *path, *hash; | |||
DIR *dir; | DIR *dir; | |||
struct dirent *d; | struct dirent *d; | |||
struct stat st; | struct stat st; | |||
string_t *str; | string_t *str; | |||
size_t dir_len, hash_len; | size_t dir_len, hash_len; | |||
if (argc < 3 || strlen(argv[2]) < 4) | if (!doveadm_cmd_param_str(cctx, "root-dir", &rootdir) || | |||
help(&doveadm_cmd_sis_find); | !doveadm_cmd_param_str(cctx, "hash", &hash) || | |||
strlen(hash) < 4) | ||||
help_ver2(&doveadm_cmd_sis_find); | ||||
rootdir = argv[1]; | ||||
if (stat(rootdir, &st) < 0) { | if (stat(rootdir, &st) < 0) { | |||
if (errno == ENOENT) | if (errno == ENOENT) | |||
i_fatal("Attachment dir doesn't exist: %s", rootdir); | i_fatal("Attachment dir doesn't exist: %s", rootdir); | |||
i_fatal("stat(%s) failed: %m", rootdir); | i_fatal("stat(%s) failed: %m", rootdir); | |||
} | } | |||
hash = argv[2]; | ||||
hash_len = strlen(hash); | hash_len = strlen(hash); | |||
path = sis_get_dir(rootdir, hash); | path = sis_get_dir(rootdir, hash); | |||
str = t_str_new(256); | str = t_str_new(256); | |||
str_append(str, path); | str_append(str, path); | |||
str_append_c(str, '/'); | str_append_c(str, '/'); | |||
dir_len = str_len(str); | dir_len = str_len(str); | |||
dir = opendir(path); | dir = opendir(path); | |||
if (dir == NULL) { | if (dir == NULL) { | |||
skipping to change at line 315 | skipping to change at line 313 | |||
if (strncmp(d->d_name, hash, hash_len) == 0) { | if (strncmp(d->d_name, hash, hash_len) == 0) { | |||
str_truncate(str, dir_len); | str_truncate(str, dir_len); | |||
str_append(str, d->d_name); | str_append(str, d->d_name); | |||
doveadm_print(str_c(str)); | doveadm_print(str_c(str)); | |||
} | } | |||
} | } | |||
if (closedir(dir) < 0) | if (closedir(dir) < 0) | |||
i_error("closedir(%s) failed: %m", path); | i_error("closedir(%s) failed: %m", path); | |||
} | } | |||
struct doveadm_cmd doveadm_cmd_sis_deduplicate = { | struct doveadm_cmd_ver2 doveadm_cmd_sis_deduplicate = { | |||
cmd_sis_deduplicate, "sis deduplicate", "<root dir> <queue dir>" | .name = "sis deduplicate", | |||
.cmd = cmd_sis_deduplicate, | ||||
.usage = "<root dir> <queue dir>", | ||||
DOVEADM_CMD_PARAMS_START | ||||
DOVEADM_CMD_PARAM('\0', "root-dir", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | ||||
DOVEADM_CMD_PARAM('\0', "queue-dir", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | ||||
DOVEADM_CMD_PARAMS_END | ||||
}; | }; | |||
struct doveadm_cmd doveadm_cmd_sis_find = { | struct doveadm_cmd_ver2 doveadm_cmd_sis_find = { | |||
cmd_sis_find, "sis find", "<root dir> <hash>" | .name = "sis find", | |||
.cmd = cmd_sis_find, | ||||
.usage = "<root dir> <hash>", | ||||
DOVEADM_CMD_PARAMS_START | ||||
DOVEADM_CMD_PARAM('\0', "root-dir", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | ||||
DOVEADM_CMD_PARAM('\0', "hash", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | ||||
DOVEADM_CMD_PARAMS_END | ||||
}; | }; | |||
End of changes. 9 change blocks. | ||||
15 lines changed or deleted | 25 lines changed or added |