Missingmew 5 лет назад
Родитель
Сommit
17aea01a58
3 измененных файлов с 15 добавлено и 3 удалено
  1. 1 0
      cli/include/fileman.h
  2. 7 1
      cli/src/cmdman.cpp
  3. 7 2
      cli/src/fileman.cpp

+ 1 - 0
cli/include/fileman.h

@@ -31,6 +31,7 @@ public:
 	void closeGet();
 	std::string getPutName();
 	std::string getGetName();
+	void cancelPut();
 	// closes and deletes getfile
 	void cancelGet();
 

+ 7 - 1
cli/src/cmdman.cpp

@@ -281,15 +281,18 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
 		// the number of remaining chunks received from the daemon does not equal the number stored at the client side		
 		retval.type = error;
 		retval.msg = std::string("File upload failed: Server reports number of remaining chunks as ") + std::to_string(root["received"].asInt()) + " but actual number is " + std::to_string(fileman.getPutChunksRemaining());
+		fileman.cancelPut();
 	} else if(root["cancel"].asBool()) {
 		retval.type = error;
 		retval.msg = "File upload cancelles: Server reports: " + root["error"].asString();
+		fileman.cancelPut();
 	} else if(root["file"].asString() != fileman.getPutName()) {
 		retval.type = error;
 		retval.msg = "File upload request failed: Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getPutName();
+		fileman.cancelPut();
 	} else {
 		// sent successfully
-		if(root["received"].asInt() < 0) {
+		if(!root["received"].asInt()) {
 			// everything sent
 			retval.type = notsend;
 			retval.msg = "succesfully uploaded file " + fileman.getPutName();
@@ -329,12 +332,15 @@ CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
 	if(root["remaining"].asInt() != fileman.getGetRemainingChunks()) {
 		retval.type = error;
 		retval.msg = std::string("File download failed: Server reports number of remaining chunks as ") + std::to_string(root["remaining"].asInt()) + " but actual number is " + std::to_string(fileman.getGetRemainingChunks());
+		fileman.cancelGet();
 	} else if(root["cancel"].asBool()) {
 		retval.type = error;
 		retval.msg = "File download cancelled: Server reports: " + root["error"].asString();
+		fileman.cancelGet();
 	} else if(root["file"].asString() != fileman.getGetName()) {
 		retval.type = error;
 		retval.msg = "File download failed: Server reports filename " + root["file"].asString() + " but actual filename is " + fileman.getGetName();
+		fileman.cancelGet();
 	} else {
 		fileman.writeBase64(root["data"].asString());
 		// loaded successfully

+ 7 - 2
cli/src/fileman.cpp

@@ -26,7 +26,7 @@ bool FileMan::openPut(const std::string &name) {
 		size_t size = putfile.tellg();
 		putsize = size;
 		putchunks = size / max_read_len + ((size % max_read_len) ? 1 : 0);
-		putchunksRemaining = putchunks-1;
+		putchunksRemaining = putchunks;
 		putfile.seekg(std::ios::beg);
 		return true;
 	}
@@ -53,6 +53,11 @@ void FileMan::closeGet() {
 	getfile.close();
 }
 
+void FileMan::cancelPut() {
+	if(isPutting()) {
+		closePut();
+	}
+}
 
 void FileMan::cancelGet() {
 	if(isGetting()) {
@@ -80,7 +85,7 @@ int FileMan::getGetRemainingChunks() {
 
 void FileMan::setGetChunks(int chunks) {
 	getchunks = chunks;
-	getchunksRemaining = chunks;
+	getchunksRemaining = chunks-1;
 }
 
 std::vector<char> FileMan::readPut() {