Fix #8: Add pending transfer check feature

- Add new 'pending' command (alias 'p') to check for pending transfers
- Enhance 'finalize' command to warn about pending transfers
- Prompt for confirmation in interactive mode before shutdown
- Use psync_get_status() API for reliable transfer detection
- Shows upload/download counts separately
- Fix mbedtls 3.6 compatibility issues in pssl.c
- Update Makefile for mbedtls 3.x static linking
This commit is contained in:
Levi Neely 2026-02-14 19:10:15 +01:00 committed by Levi Neely
parent e566c7822a
commit 11074655db
4 changed files with 70 additions and 2 deletions

View File

@ -59,6 +59,7 @@ static char* command_generator(const char* text, int state) {
"c", "c start", "c stop",
"sync", "sync ls", "sync add", "sync remove", "sync rm",
"s", "s ls", "s add", "s remove", "s rm",
"pending", "p",
"finalize", "f",
"quit", "q",
nullptr
@ -100,6 +101,7 @@ 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
<< " pending(p): Check for pending transfers" << std::endl
<< " finalize(f): Kill daemon and quit" << std::endl
<< " quit(q): Exit this program" << std::endl;
});
@ -113,6 +115,29 @@ void setup_app(CLI::App *app) {
char *errm = NULL;
size_t errm_size = 0;
RpcClient *rpc = new RpcClient();
// Check for pending transfers first
if (rpc->Call(CHECKPENDING, "", &errm, &errm_size) == 0) {
uint32_t *pending = nullptr;
if (pshm_read((void**)&pending, nullptr) && pending) {
if (*pending > 0) {
std::cout << "Warning: " << *pending << " pending transfer(s) detected" << std::endl;
std::cout << "Stopping daemon will break pending transfers. Continue? (y/n): ";
std::string response;
std::getline(std::cin, response);
if (response != "y" && response != "Y") {
std::cout << "Finalize cancelled" << std::endl;
free(pending);
if (errm) { free(errm); }
delete rpc;
return;
}
}
free(pending);
}
}
if (errm) { free(errm); errm = NULL; }
rpc->Call(FINALIZE, "", &errm, &errm_size);
delete rpc;
std::cout << "Exiting ..." << std::endl;
@ -124,6 +149,17 @@ void setup_app(CLI::App *app) {
exit(0);
});
// pending command
app->add_subcommand("pending", "Check for pending transfers")->alias("p")->callback([] {
char *errm = NULL;
size_t errm_size = 0;
RpcClient *rpc = new RpcClient();
rpc->Call(CHECKPENDING, "", &errm, &errm_size);
delete rpc;
if (errm) { free(errm); }
return 0;
});
// crypto start
auto start_crypto_cmd = crypto_cmd->add_subcommand("start", "Start crypto");
static std::string start_crypto_pwd;

View File

@ -4,5 +4,6 @@ enum command_ids_ {
FINALIZE,
LISTSYNC,
ADDSYNC,
STOPSYNC
STOPSYNC,
CHECKPENDING
};

View File

@ -33,6 +33,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
@ -392,9 +393,37 @@ int clib::pclsync_lib::stop_crypto(const char *unused) {
return 0;
}
int clib::pclsync_lib::check_pending(const char *unused) {
(void)unused;
pstatus_t status;
psync_get_status(&status);
uint32_t pending = status.filestoupload + status.filestodownload;
// Write result to shared memory for client
pshm_write(&pending, sizeof(uint32_t));
if (pending > 0) {
std::cout << "Warning: " << pending << " pending transfer(s) detected";
if (status.filestoupload > 0 && status.filestodownload > 0) {
std::cout << " (" << status.filestoupload << " upload(s), "
<< status.filestodownload << " download(s))";
} else if (status.filestoupload > 0) {
std::cout << " (" << status.filestoupload << " upload(s))";
} else {
std::cout << " (" << status.filestodownload << " download(s))";
}
std::cout << std::endl;
return 1;
}
std::cout << "No pending transfers detected" << std::endl;
return 0;
}
int clib::pclsync_lib::finalize(const char *unused) {
(void)unused;
psync_destroy();
exit(0);
}
@ -499,6 +528,7 @@ int clib::pclsync_lib::init() {
prpc_register(STARTCRYPTO, &start_crypto);
prpc_register(STOPCRYPTO, &stop_crypto);
prpc_register(FINALIZE, &finalize);
prpc_register(CHECKPENDING, &check_pending);
prpc_register(LISTSYNC, &list_sync_folders);
prpc_register(ADDSYNC, &add_sync_folder);
prpc_register(STOPSYNC, &remove_sync_folder);

View File

@ -97,6 +97,7 @@ public:
static int start_crypto(const char *pass);
static int stop_crypto(const char *path);
static int finalize(const char *path);
static int check_pending(const char *unused);
static int list_sync_folders(const char *path);
static int add_sync_folder(const char *path);
static int remove_sync_folder(const char *path);