diff --git a/program/Source/cloud/FTPAdapter.cpp b/program/Source/cloud/FTPAdapter.cpp index b95256b0ca86ddf4886c98c8acf907b943f89156..af6796d4ffb65f22454870a89d7e88884a5de895 100644 --- a/program/Source/cloud/FTPAdapter.cpp +++ b/program/Source/cloud/FTPAdapter.cpp @@ -98,7 +98,7 @@ shared_ptr<Fragment> FTPAdapter::download(CloudFile cloudFile) { try { session.setFileType(FTPClientSession::TYPE_BINARY); - auto& is = session.beginDownload(cloudFile.getCloudFileID()); + auto& is = session.beginDownload(ROOT + cloudFile.getCloudFileID()); StreamCopier::copyStream(is, file); session.endDownload(); return make_shared<Fragment>(cloudFile);; @@ -117,7 +117,7 @@ bool FTPAdapter::deleteFile(CloudFile cloudFile) { try { - session.remove(cloudFile.getCloudFileID()); + session.remove(ROOT + cloudFile.getCloudFileID()); return true; } catch (FTPException& e) @@ -138,7 +138,7 @@ long FTPAdapter::getSize(CloudFile cloudFile) { FTPClientSession session(HOST, FTPClientSession::FTP_PORT, USERNAME, PASSWORD); string response; - session.sendCommand("SIZE " + cloudFile.getCloudFileID(), response); + session.sendCommand("SIZE " + ROOT + cloudFile.getCloudFileID(), response); if (response.find("213 ") != string::npos) return stol(response.substr(4)); diff --git a/program/Source/dataAccess/ComputeOnPi.cpp b/program/Source/dataAccess/ComputeOnPi.cpp index e58b19365bf64e0afdfb4e0e50318689f1adda87..d6faea6c98b9e38d0603c6c754b4aa6b33c5c9dd 100644 --- a/program/Source/dataAccess/ComputeOnPi.cpp +++ b/program/Source/dataAccess/ComputeOnPi.cpp @@ -14,12 +14,14 @@ ReturnableFile ComputeOnPi::getFile(FileDescriptor fileDescriptor) { //TODO: change HomeNetworkCommunications' getFileRemote's attribute's type to fileDescriptor ReturnableFile resultFile(fileDescriptor.getFileID()); - if (cloudFileSystem.getHomeNetworkCommunications()->getFileRemote(fileDescriptor.getFileID())){ + /*if (cloudFileSystem.getHomeNetworkCommunications()->getFileRemote(fileDescriptor.getFileID())){ resultFile.setValid(true); } else { resultFile.setErrorMessage("Could't download file"); } - return resultFile; + return resultFile;*/ + + return cloudFileSystem.getHomeNetworkCommunications()->getFileRemote(fileDescriptor.getFileID()); } \ No newline at end of file diff --git a/program/Source/dataAccess/Encoder.cpp b/program/Source/dataAccess/Encoder.cpp index 2907d1bfe97d3fce995f263382767f27e34ba8b2..f9186758f5c738be53ab2d8cae6aa9a14c2d7c7b 100644 --- a/program/Source/dataAccess/Encoder.cpp +++ b/program/Source/dataAccess/Encoder.cpp @@ -35,8 +35,9 @@ FileDescriptor* Encoder::encode(string localFileID, string destinationFileID) { string encode_filename = dataFolder + localFileID; //check if file exists - if (!exists(encode_filename)){ - throw CloudException("No such file exists"); + if (!exists(encode_filename)) + { + throw CloudException("No such file exists: " + dataFolder + localFileID); } auto encoded = new FileDescriptor(localFileID); diff --git a/program/Source/networking/HomeNetworkCommunications.cpp b/program/Source/networking/HomeNetworkCommunications.cpp index 81c43491fbf44946cc4306a901edac09bd9b53fa..bd92a6c03f79c488c8465c695a2bbad4e6781309 100644 --- a/program/Source/networking/HomeNetworkCommunications.cpp +++ b/program/Source/networking/HomeNetworkCommunications.cpp @@ -9,6 +9,7 @@ #include <Poco/Net/DatagramSocket.h> #include "../app/Application.h" #include "FileServerConnectionFactory.h" +#include "../fileModel/ReturnableFile.h" using namespace std; using namespace Poco; @@ -73,13 +74,19 @@ bool HomeNetworkCommunications::addFileRemote(string fileID) return false; } -bool HomeNetworkCommunications::getFileRemote(string fileID) +ReturnableFile HomeNetworkCommunications::getFileRemote(string fileID) { LOG_ENTER_EXIT; + ReturnableFile result(fileID); + refresh(); - if (!piAvaliable) - return false; + if (!piAvaliable) + { + result.setErrorMessage("Remote server not available"); + return result; + } + int msgType; int fileNameSize = fileID.size(); @@ -96,8 +103,11 @@ bool HomeNetworkCommunications::getFileRemote(string fileID) // Get server answer socket.receiveBytes(&msgType, sizeof(msgType)); - if (msgType != OK_ANS) - return false; + if (msgType != OK_ANS) + { + result.setErrorMessage("Serverside error"); + return result; + } // Get file char buffer[100000]; @@ -111,7 +121,8 @@ bool HomeNetworkCommunications::getFileRemote(string fileID) fileSize -= receivedBytes; } - return true; + result.setValid(true); + return result; } void HomeNetworkCommunications::refresh() diff --git a/program/Source/networking/HomeNetworkCommunications.h b/program/Source/networking/HomeNetworkCommunications.h index 853c727c8987fded67a7714948d562ff5937f608..37b887833948ba117f4d9049fbe382e87261b6e5 100644 --- a/program/Source/networking/HomeNetworkCommunications.h +++ b/program/Source/networking/HomeNetworkCommunications.h @@ -4,6 +4,7 @@ #include <string> #include <Poco/Net/IPAddress.h> +class ReturnableFile; class Application; namespace Poco { @@ -51,7 +52,7 @@ public: * Sends a file to the PI be added remotely * @param fileID ID of the file to be added */ - bool getFileRemote(std::string fileID); + ReturnableFile getFileRemote(std::string fileID); /** * Checks if the pi is avaliable