[Box Backup-dev] COMMIT r477 - box/chris/general/bin/bbackupctl

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Mon Feb 20 00:01:38 GMT 2006


Author: chris
Date: 2006-02-20 00:01:35 +0000 (Mon, 20 Feb 2006)
New Revision: 477

Modified:
   box/chris/general/bin/bbackupctl/bbackupctl.cpp
Log:
* bbackupctl.cpp
- Added a new "sync-and-wait" command that forces a sync and waits for
  it to finish


Modified: box/chris/general/bin/bbackupctl/bbackupctl.cpp
===================================================================
--- box/chris/general/bin/bbackupctl/bbackupctl.cpp	2006-02-20 00:01:05 UTC (rev 476)
+++ box/chris/general/bin/bbackupctl/bbackupctl.cpp	2006-02-20 00:01:35 UTC (rev 477)
@@ -38,6 +38,7 @@
 	"  reload -- reload daemon configuration\n"
 	"  terminate -- terminate daemon now\n"
 	"  wait-for-sync -- wait until the next sync starts, then exit\n"
+	"  sync-and-wait -- start sync, wait until it finishes, then exit\n"
 	);
 	exit(1);
 }
@@ -196,8 +197,29 @@
 			   autoBackup?"true":"false", updateStoreInterval, minimumFileAge, maxUploadWait);
 	}
 
+	std::string stateLine;
+	if(!getLine.GetLine(stateLine) || getLine.IsEOF())
+	{
+#if defined WIN32 && ! defined NDEBUG
+		syslog(LOG_ERR, "Failed to receive state line from daemon");
+#else
+		printf("Failed to receive state line from daemon\n");
+#endif
+		return 1;
+	}
+
+	// Decode it
+	int currentState;
+	if(::sscanf(stateLine.c_str(), "state %d", &currentState) != 1)
+	{
+		printf("State line didn't decode\n");
+		return 1;
+	}
+
 	// Is the command the "wait for sync to start" command?
 	bool areWaitingForSync = false;
+	bool areWaitingForSyncEnd = false;
+
 	if(::strcmp(argv[0], "wait-for-sync") == 0)
 	{
 		// Check that it's not in non-automatic mode, because then it'll never start
@@ -210,6 +232,20 @@
 		// Yes... set the flag so we know what we're waiting for a sync to start
 		areWaitingForSync = true;
 	}
+	else if (::strcmp(argv[0], "sync-and-wait") == 0)
+	{
+		// send a sync command
+		std::string cmd("force-sync\n");
+		connection.Write(cmd.c_str(), cmd.size());
+		connection.WriteAllBuffered();
+		areWaitingForSyncEnd = true;
+
+		if (currentState != 0)
+		{
+			printf("Waiting for current sync/error state "
+				"to finish...\n");
+		}
+	}
 	else
 	{
 		// No? Just send the command given plus a quit command.
@@ -220,6 +256,8 @@
 	
 	// Read the response
 	std::string line;
+	bool syncIsRunning = false;
+
 	while(!getLine.IsEOF() && getLine.GetLine(line))
 	{
 		if(areWaitingForSync)
@@ -234,6 +272,28 @@
 				break;
 			}		
 		}
+		else if(areWaitingForSyncEnd)
+		{
+			if(line == "start-sync")
+			{
+				printf("Sync started...\n");
+				syncIsRunning = true;
+			}
+			else if(line == "finish-sync" && syncIsRunning)
+			{
+				printf("Sync finished.\n");
+				// Send a quit command to finish nicely
+				connection.Write("quit\n", 5);
+				
+				// And we're done
+				break;
+			}
+			else if(line == "finish-sync")
+			{
+				printf("Previous sync finished.\n");
+			}
+			// daemon must still be busy
+		}
 		else
 		{
 			// Is this an OK or error line?




More information about the Boxbackup-dev mailing list