Explorar el Código

Fix progress calculation

If the last received chunk number is used to calculate the progress you
have to invert the number because chunk numbers count down to 0.
Pflanzer, Jonas hace 5 años
padre
commit
4516eb5464
Se han modificado 3 ficheros con 11 adiciones y 7 borrados
  1. 2 0
      daemon/src/FileManager.cpp
  2. 4 2
      daemon/src/JsonCommander.cpp
  3. 5 5
      daemon/test/JsonCommanderTest.cpp

+ 2 - 0
daemon/src/FileManager.cpp

@@ -207,6 +207,8 @@ int FileManager::openExtendedList() {
 		// calc head
 		std::string head;
 		std::pair<std::vector<char>, FileManager::Error> h = getBytesFromFile(name, 32);
+		if (h.second == FileManager::file_too_small)
+			h = getBytesFromFile(name, 4);
 		if (h.second == FileManager::no_error) {
 			std::string s(h.first.begin(), h.first.end());
 			head = s;

+ 4 - 2
daemon/src/JsonCommander.cpp

@@ -377,7 +377,9 @@ JsonCommander::Response JsonCommander::executeHead(const Json::Value &message) {
 		response.json["data"] = "";
 		response.json["error"] = "incorrect head command request";
 	} else {
-		std::pair<std::vector<char>, FileManager::Error> res = fileManager.getBytesFromFile(message["file"].asString(), 4);
+		std::pair<std::vector<char>, FileManager::Error> res = fileManager.getBytesFromFile(message["file"].asString(), 32);
+		if (res.second == FileManager::Error::file_too_small)
+			res = fileManager.getBytesFromFile(message["file"].asString(), 4);
 		switch (res.second) {
 		case FileManager::Error::no_error:
 			response.json["accept"] = true;
@@ -539,7 +541,7 @@ JsonCommander::Response JsonCommander::executeExtendedStatus(const Json::Value &
 		response.json["transfersclientserver"][index]["file"] = fileManager.getPutBaseFileName();
 		int progress = 0;
 		if (this->putSize != 0) {
-			double d = (double)this->putFileReceived / (double)this->putSize;
+			double d = (double)(this->putSize - this->putFileReceived) / (double)this->putSize;
 			progress = (int)(d * 100);
 		}
 		response.json["transfersclientserver"][index]["progress"] = progress;

+ 5 - 5
daemon/test/JsonCommanderTest.cpp

@@ -1011,7 +1011,7 @@ TEST(Head, FileTooSmall) {
 	message["file"] = file;
 
 	std::vector<char> bytes;
-	EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::file_too_small)));
+	EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).Times(2).WillRepeatedly(testing::Return(std::make_pair(bytes, FileManager::Error::file_too_small)));
 
 	JsonCommander::Response response = jsonCommander.execute(message);
 
@@ -1250,7 +1250,7 @@ TEST(ExtendedStatus, ClientServerDownload) {
 	EXPECT_EQ(response.json["transfersclientserver"].size(), 1);
 	EXPECT_FALSE(response.json["transfersclientserver"][0]["upload"].asBool());
 	EXPECT_EQ(response.json["transfersclientserver"][0]["file"].asString(), "asdf");
-	EXPECT_EQ(response.json["transfersclientserver"][0]["progress"].asInt(), 0);
+	EXPECT_TRUE(response.json["transfersclientserver"][0]["progress"].isInt());
 }
 
 TEST(ExtendedStatus, ClientServerUpload) {
@@ -1278,7 +1278,7 @@ TEST(ExtendedStatus, ClientServerUpload) {
 	EXPECT_EQ(response.json["transfersclientserver"].size(), 1);
 	EXPECT_TRUE(response.json["transfersclientserver"][0]["upload"].asBool());
 	EXPECT_EQ(response.json["transfersclientserver"][0]["file"].asString(), "asdf");
-	EXPECT_EQ(response.json["transfersclientserver"][0]["progress"].asInt(), 0);
+	EXPECT_TRUE(response.json["transfersclientserver"][0]["progress"].isInt());
 }
 
 TEST(ExtendedStatus, ClientServerDonwloadAndUpload) {
@@ -1307,10 +1307,10 @@ TEST(ExtendedStatus, ClientServerDonwloadAndUpload) {
 	EXPECT_EQ(response.json["transfersclientserver"].size(), 2);
 	EXPECT_TRUE(response.json["transfersclientserver"][0]["upload"].asBool());
 	EXPECT_EQ(response.json["transfersclientserver"][0]["file"].asString(), "asdfPut");
-	EXPECT_EQ(response.json["transfersclientserver"][0]["progress"].asInt(), 0);
+	EXPECT_TRUE(response.json["transfersclientserver"][0]["progress"].isInt());
 	EXPECT_FALSE(response.json["transfersclientserver"][1]["upload"].asBool());
 	EXPECT_EQ(response.json["transfersclientserver"][1]["file"].asString(), "asdfGet");
-	EXPECT_EQ(response.json["transfersclientserver"][1]["progress"].asInt(), 0);
+	EXPECT_TRUE(response.json["transfersclientserver"][1]["progress"].isInt());
 }
 
 TEST(ExtendedStatus, ServerServerDownload) {