Преглед на файлове

Merge branch '51-get-file-fix' into 'develop'

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

Closes #51

See merge request tobias.wach/ccats!56
Serdyukov, Denys преди 4 години
родител
ревизия
abe8e6d54d
променени са 1 файла, в които са добавени 28 реда и са изтрити 14 реда
  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";
+			}
 		}
 	}