@@ -535,7 +535,9 @@ static int main(int argc, char **argv)
535535namespace global {
536536
537537static char *g_arg_username, *g_arg_userdir;
538+ static unsigned int g_continuous_mode;
538539static constexpr HXoption g_options_table[] = {
540+ {nullptr , ' c' , HXTYPE_NONE, &g_continuous_mode, {}, {}, {}, " Do not stop on errors" },
539541 {nullptr , ' d' , HXTYPE_STRING, &g_arg_userdir, nullptr , nullptr , 0 , " Directory of the mailbox" , " DIR" },
540542 {nullptr , ' u' , HXTYPE_STRING, &g_arg_username, nullptr , nullptr , 0 , " Username of store to import to" , " EMAILADDR" },
541543 HXOPT_AUTOHELP,
@@ -561,6 +563,7 @@ static int help()
561563 fprintf (stderr, " Usage: gromox-mbop [global-options] command [command-options] [command-args...]\n " );
562564 fprintf (stderr, " Global options:\n " );
563565 fprintf (stderr, " \t -? Global help (this text)\n " );
566+ fprintf (stderr, " \t -c Continus operation mode\n " );
564567 fprintf (stderr, " \t -u emailaddr/-d directory Name of/path to mailbox\n " );
565568 command_overview ();
566569 fprintf (stderr, " Command options:\n " );
@@ -682,42 +685,53 @@ static int main(int argc, char **argv)
682685 auto ret = gi_startup_client (g_numthreads);
683686 if (ret != 0 )
684687 return ret;
688+ auto cl_1 = make_scope_exit (gi_shutdown);
685689 ret = EXIT_SUCCESS;
686690 using Sem = std::counting_semaphore<1 >;
687691 std::vector<std::future<void >> futs;
688692 Sem sem (g_numthreads);
693+
689694 if (strcmp (argv[0 ], " ping" ) == 0 ) {
690695 if (HX_getopt5 (empty_options_table, argv, nullptr , nullptr ,
691696 HXOPT_RQ_ORDER | HXOPT_USAGEONERR) != HXOPT_ERR_SUCCESS)
692697 return EXIT_PARAM;
693698 for (auto &&[username, maildir] : ul) {
694699 sem.acquire ();
695- futs.emplace_back (std::async ([](std::string *maildir, Sem *sem) {
696- exmdb_client::ping_store (maildir->c_str ());
700+ if (ret != EXIT_SUCCESS && !global::g_continuous_mode)
701+ break ;
702+ futs.emplace_back (std::async ([](std::string *maildir, Sem *sem, int *ret) {
703+ if (!exmdb_client::ping_store (maildir->c_str ()))
704+ *ret = EXIT_FAILURE;
697705 sem->release ();
698- }, &maildir, &sem));
706+ }, &maildir, &sem, &ret ));
699707 }
700708 } else if (strcmp (argv[0 ], " unload" ) == 0 ) {
701709 if (HX_getopt5 (empty_options_table, argv, nullptr , nullptr ,
702710 HXOPT_RQ_ORDER | HXOPT_USAGEONERR) != HXOPT_ERR_SUCCESS)
703711 return EXIT_PARAM;
704712 for (auto &&[username, maildir] : ul) {
705713 sem.acquire ();
706- futs.emplace_back (std::async ([](std::string *maildir, Sem *sem) {
707- exmdb_client::unload_store (maildir->c_str ());
714+ if (ret != EXIT_SUCCESS && !global::g_continuous_mode)
715+ return ret;
716+ futs.emplace_back (std::async ([](std::string *maildir, Sem *sem, int *ret) {
717+ if (!exmdb_client::unload_store (maildir->c_str ()))
718+ *ret = EXIT_FAILURE;
708719 sem->release ();
709- }, &maildir, &sem));
720+ }, &maildir, &sem, &ret ));
710721 }
711722 } else if (strcmp (argv[0 ], " vacuum" ) == 0 ) {
712723 if (HX_getopt5 (empty_options_table, argv, nullptr , nullptr ,
713724 HXOPT_RQ_ORDER | HXOPT_USAGEONERR) != HXOPT_ERR_SUCCESS)
714725 return EXIT_PARAM;
715726 for (auto &&[username, maildir] : ul) {
716727 sem.acquire ();
717- futs.emplace_back (std::async ([](std::string *maildir, Sem *sem) {
718- exmdb_client::vacuum (maildir->c_str ());
728+ if (ret != EXIT_SUCCESS && !global::g_continuous_mode)
729+ return ret;
730+ futs.emplace_back (std::async ([](std::string *maildir, Sem *sem, int *ret) {
731+ if (!exmdb_client::vacuum (maildir->c_str ()))
732+ *ret = EXIT_FAILURE;
719733 sem->release ();
720- }, &maildir, &sem));
734+ }, &maildir, &sem, &ret ));
721735 }
722736 } else {
723737 for (auto &&[username, maildir] : ul) {
@@ -727,11 +741,11 @@ static int main(int argc, char **argv)
727741 g_storedir = g_storedir_s.c_str ();
728742 ret = global::main2 (argc, argv);
729743 if (ret == EXIT_PARAM)
730- break ;
744+ return ret;
745+ else if (ret != EXIT_SUCCESS && !global::g_continuous_mode)
746+ return ret;
731747 }
732748 }
733- futs.clear ();
734- gi_shutdown ();
735749 return ret;
736750}
737751
0 commit comments