subscription-file.c revision 728a9c39b63b48f17600e6a1e5ebfc93d0896a24
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (C) 2002-2003 Timo Sirainen */
87a6b7df39d6822a5a8289a62f32deabff9b75e4Timo Sirainen#define SUBSCRIPTION_FILE_ESTALE_RETRY_COUNT NFS_ESTALE_RETRY_COUNT
da2aa032ccfa8e7e4a4380ef738014549f4d2c2dTimo Sirainenstatic void subsfile_set_syscall_error(struct mailbox_list *list,
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen mailbox_list_set_error(list, "Permission denied");
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen "%s failed with subscription file %s: %m",
09801f106cd531a28b4e03ec665e44c421264560Timo Sirainenstatic const char *next_line(struct mailbox_list *list, const char *path,
212a34c06ff45952c008ae9eec387ced783de6cfPhil Carmody while ((line = i_stream_next_line(input)) == NULL) {
a9a928e40e3b691924c8e5e444e3e1a4320aa3bdStephan Bosch (input->stream_errno != ESTALE || !ignore_estale)) {
a9a928e40e3b691924c8e5e444e3e1a4320aa3bdStephan Bosch /* mailbox name too large */
bdcb00145ad87765e3fd22d4ebc4d2c029a326b9Timo Sirainen "Subscription file %s contains lines longer "
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainenint subsfile_set_subscribed(struct mailbox_list *list, const char *path,
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen const char *temp_prefix, const char *name, bool set)
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen (list->flags & MAILBOX_LIST_FLAG_DOTLOCK_USE_EXCL) != 0;
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainen dotlock_set.timeout = SUBSCRIPTION_FILE_LOCK_TIMEOUT;
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen dotlock_set.stale_timeout = SUBSCRIPTION_FILE_CHANGE_TIMEOUT;
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen fd_out = file_dotlock_open(&dotlock_set, path, 0, &dotlock);
46ce4d9273e6df12ef1912bbdb1c8b84b104f394Timo Sirainen "Timeout waiting for subscription file lock");
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen subsfile_set_syscall_error(list, "open()", path);
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen output = o_stream_create_file(fd_out, default_pool,
463f6ea04af934a68facaca0ff089bc306de3f98Timo Sirainen subsfile_set_syscall_error(list, "write()", path);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* append subscription */
e0fab14602b73ff590b2a9c5d9e67e2dfb5d1f9eTimo Sirainen subsfile_set_syscall_error(list, "write()", path);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen subsfile_set_syscall_error(list, "fsync()", path);
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen if (failed || (set && found) || (!set && !found)) {
7d207b1e77a7b5e3fda640e353acfc86d261fedfTimo Sirainen if (file_dotlock_replace(&dotlock, flags) < 0) {
6a170d6d781094bdc75f027b6456dde160fbde39Timo Sirainensubsfile_list_init(struct mailbox_list *list, const char *path)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen ctx = p_new(pool, struct subsfile_list_context, 1);
6f08b98ac63c25b747120d0c8f8e319b4e26ab0fTimo Sirainen subsfile_set_syscall_error(list, "open()", path);
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainenint subsfile_list_deinit(struct subsfile_list_context *ctx)
09142ea11662746ea07475b1a4f69a6a406fb996Phil Carmodyconst char *subsfile_list_next(struct subsfile_list_context *ctx)
09142ea11662746ea07475b1a4f69a6a406fb996Phil Carmody const char *line;
09142ea11662746ea07475b1a4f69a6a406fb996Phil Carmody unsigned int i;
09142ea11662746ea07475b1a4f69a6a406fb996Phil Carmody for (i = 0;; i++) {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen line = next_line(ctx->list, ctx->path, ctx->input, &ctx->failed,
4c096615cb86a826fda377b87df22c579bfe5525Timo Sirainen /* Reopen the subscription file and re-send everything.
4c096615cb86a826fda377b87df22c579bfe5525Timo Sirainen this isn't the optimal behavior, but it's allowed by
4c096615cb86a826fda377b87df22c579bfe5525Timo Sirainen IMAP and this way we don't have to read everything into
4c096615cb86a826fda377b87df22c579bfe5525Timo Sirainen memory or try to play any guessing games. */
return NULL;
TRUE);
return line;