Fix #67: Add sync pause and sync resume commands

Wire psync_pause() and psync_resume() from the C library into the RPC
command layer, registering SYNCPAUSE and SYNCRESUME handlers and exposing
them as 'sync pause' and 'sync resume' CLI subcommands.

Note: daemon quit is already handled by the existing 'finalize' command,
which calls psync_destroy() and exits the daemon process cleanly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Levi Neely 2026-03-02 20:07:40 +01:00
parent 0a697794dd
commit 009b71be63
4 changed files with 57 additions and 3 deletions

View File

@ -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 <localpath> <remotepath>: Add sync folder" << std::endl
<< " remove(rm) <folderid>: 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;

View File

@ -5,5 +5,7 @@ enum command_ids_ {
LISTSYNC,
ADDSYNC,
STOPSYNC,
CHECKPENDING
CHECKPENDING,
SYNCPAUSE,
SYNCRESUME
};

View File

@ -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;
}

View File

@ -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();