]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
plugins/fts: Restore fts_indexer_cmd
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 8 Jul 2021 08:10:38 +0000 (11:10 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 8 Jul 2021 08:13:23 +0000 (11:13 +0300)
It was removed in cf114f90e0ba25c18db846ee582e3a130bd52949 and that
broke some FTS plugins.

src/plugins/fts/fts-indexer.c

index 4fbefb0e6bc9eb94fdf29aa9c3f9506a7af4e43f..c203771d5dc949c05d9f1aeeda5789949c17af56 100644 (file)
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "ioloop.h"
 #include "connection.h"
+#include "write-full.h"
 #include "istream.h"
 #include "ostream.h"
 #include "strescape.h"
@@ -267,3 +268,29 @@ int fts_indexer_init(struct fts_backend *backend, struct mailbox *box,
        *ctx_r = ctx;
        return ctx->failed || ret < 0 ? -1 : 1;
 }
+
+#define INDEXER_HANDSHAKE "1\t0\tindexer\tindexer\n"
+
+int fts_indexer_cmd(struct mail_user *user, const char *cmd,
+                   const char **path_r)
+{
+       const char *path;
+       int fd;
+
+       path = t_strconcat(user->set->base_dir,
+                          "/"INDEXER_SOCKET_NAME, NULL);
+       fd = net_connect_unix_with_retries(path, 1000);
+       if (fd == -1) {
+               i_error("net_connect_unix(%s) failed: %m", path);
+               return -1;
+       }
+
+       cmd = t_strconcat(INDEXER_HANDSHAKE, cmd, NULL);
+       if (write_full(fd, cmd, strlen(cmd)) < 0) {
+               i_error("write(%s) failed: %m", path);
+               i_close_fd(&fd);
+               return -1;
+       }
+       *path_r = path;
+       return fd;
+}