diff --git a/control_tools.cpp b/control_tools.cpp index e8bf717..59fd253 100644 --- a/control_tools.cpp +++ b/control_tools.cpp @@ -57,8 +57,8 @@ static char* command_generator(const char* text, int state) { "help", "?", "crypto", "crypto start", "crypto stop", "c", "c start", "c stop", - "sync", "sync ls", "sync add", "sync remove", "sync rm", - "s", "s ls", "s add", "s remove", "s rm", + "sync", "sync ls", "sync add", "sync remove", "sync rm", "sync pause", "sync resume", + "s", "s ls", "s add", "s remove", "s rm", "s pause", "s resume", "pending", "p", "finalize", "f", "quit", "q", @@ -101,6 +101,8 @@ void setup_app(CLI::App *app) { << " list(ls): List sync folders" << std::endl << " add : Add sync folder" << std::endl << " remove(rm) : Remove sync folder" << std::endl + << " pause: Pause syncing (filesystem remains mounted)" << std::endl + << " resume: Resume syncing" << std::endl << " pending(p): Check for pending transfers" << std::endl << " finalize(f): Kill daemon and quit" << std::endl << " quit(q): Exit this program" << std::endl; @@ -268,6 +270,40 @@ void setup_app(CLI::App *app) { return 0; }); + // sync pause + sync_cmd->add_subcommand("pause", "Pause syncing (filesystem remains mounted)")->callback([] { + char *errm = NULL; + size_t errmsz = 0; + RpcClient *rpc = new RpcClient(); + if (int result = rpc->Call(SYNCPAUSE, "", &errm, &errmsz) != 0) { + std::cerr << "Sync pause failed: " << (errm ? errm : "no message") << std::endl; + if (errm) { free(errm); } + delete rpc; + return result; + } + delete rpc; + std::cout << "Sync paused." << std::endl; + if (errm) { free(errm); } + return 0; + }); + + // sync resume + sync_cmd->add_subcommand("resume", "Resume syncing")->callback([] { + char *errm = NULL; + size_t errmsz = 0; + RpcClient *rpc = new RpcClient(); + if (int result = rpc->Call(SYNCRESUME, "", &errm, &errmsz) != 0) { + std::cerr << "Sync resume failed: " << (errm ? errm : "no message") << std::endl; + if (errm) { free(errm); } + delete rpc; + return result; + } + delete rpc; + std::cout << "Sync resumed." << std::endl; + if (errm) { free(errm); } + return 0; + }); + // sync remove auto sync_remove_cmd = sync_cmd->add_subcommand("remove", "Remove sync folder (use ls to get folder ID)")->alias("rm"); static std::string syncrm_fid; diff --git a/pclsync/pcommands.h b/pclsync/pcommands.h index 5e3a6e0..35f07ee 100644 --- a/pclsync/pcommands.h +++ b/pclsync/pcommands.h @@ -5,5 +5,7 @@ enum command_ids_ { LISTSYNC, ADDSYNC, STOPSYNC, - CHECKPENDING + CHECKPENDING, + SYNCPAUSE, + SYNCRESUME }; diff --git a/pclsync_lib.cpp b/pclsync_lib.cpp index fb5f0b1..df2dd1e 100644 --- a/pclsync_lib.cpp +++ b/pclsync_lib.cpp @@ -473,6 +473,18 @@ int clib::pclsync_lib::finalize(const char *unused) { exit(0); } +int clib::pclsync_lib::pause_sync(const char *unused) { + (void)unused; + psync_pause(); + return 0; +} + +int clib::pclsync_lib::resume_sync(const char *unused) { + (void)unused; + psync_resume(); + return 0; +} + // path is the local and remote path delimited by '|' int clib::pclsync_lib::add_sync_folder(const char *combined_path) { if (combined_path == nullptr) { @@ -588,6 +600,8 @@ int clib::pclsync_lib::init() { prpc_register(LISTSYNC, &list_sync_folders); prpc_register(ADDSYNC, &add_sync_folder); prpc_register(STOPSYNC, &remove_sync_folder); + prpc_register(SYNCPAUSE, &pause_sync); + prpc_register(SYNCRESUME, &resume_sync); return 0; } diff --git a/pclsync_lib.h b/pclsync_lib.h index 4458290..59a05ac 100644 --- a/pclsync_lib.h +++ b/pclsync_lib.h @@ -102,6 +102,8 @@ public: static int list_sync_folders(const char *path); static int add_sync_folder(const char *path); static int remove_sync_folder(const char *path); + static int pause_sync(const char *unused); + static int resume_sync(const char *unused); int logout(); int unlink();