Browse Source

Prevent put and get if there is a put or get in progress

Sander, Paul 4 years ago
parent
commit
6c6e212156
1 changed files with 28 additions and 14 deletions
  1. 28 14
      cli/src/cmdman.cpp

+ 28 - 14
cli/src/cmdman.cpp

@@ -131,16 +131,23 @@ CmdMan::CmdRet CmdMan::cmdPut(vector<string> args) {
 		root["accept"] = false;
 		root["error"] = "not enough arguments, at least 1 argument required";
 	} else {
-		bool opened = fileman.openPut(args[0]);
-		root["file"] = fileman.getPutName();
-		if (opened) {
-			root["size"] = fileman.getPutSize();
-			root["chunks"] = fileman.getPutChunks();
-			retval.type = send;
-		} else {
+		if (fileman.isPutting()) {
 			retval.type = error;
+			root["file"] = args[0];
 			root["accept"] = false;
-			root["error"] = "couldnt open local file \"" + args[0] + "\"";
+			root["error"] = "already putting file \"" + fileman.getPutName() + "\"";
+		} else {
+			bool opened = fileman.openPut(args[0]);
+			root["file"] = fileman.getPutName();
+			if (opened) {
+				root["size"] = fileman.getPutSize();
+				root["chunks"] = fileman.getPutChunks();
+				retval.type = send;
+			} else {
+				retval.type = error;
+				root["accept"] = false;
+				root["error"] = "couldnt open local file \"" + args[0] + "\"";
+			}
 		}
 	}
 
@@ -175,14 +182,21 @@ CmdMan::CmdRet CmdMan::cmdGet(vector<string> args) {
 		root["accept"] = false;
 		root["error"] = "not enough arguments, at least 1 argument required";
 	} else {
-		bool opened = fileman.openGet(args[0]);
-		root["file"] = fileman.getGetName();
-		if (opened) {
-			retval.type = send;
-		} else {
+		if (fileman.isGetting()) {
 			retval.type = error;
+			root["file"] = args[0];
 			root["accept"] = false;
-			root["error"] = "local file \"" + args[0] + "\" already exists";
+			root["error"] = "already getting file \"" + fileman.getGetName() + "\"";
+		} else {
+			bool opened = fileman.openGet(args[0]);
+			root["file"] = fileman.getGetName();
+			if (opened) {
+				retval.type = send;
+			} else {
+				retval.type = error;
+				root["accept"] = false;
+				root["error"] = "local file \"" + args[0] + "\" already exists";
+			}
 		}
 	}