From 8f556b5f0a273ada87357a201051c0596d8222cd Mon Sep 17 00:00:00 2001 From: srsdanny <seres.dani@gmail.com> Date: Wed, 25 Nov 2015 01:45:32 +0100 Subject: [PATCH] Corrected FTPAdapter --- program/Source/cloud/FTPAdapter.cpp | 6 ++--- program/Source/dataAccess/ComputeOnPi.cpp | 6 +++-- program/Source/dataAccess/Encoder.cpp | 5 ++-- .../networking/HomeNetworkCommunications.cpp | 23 ++++++++++++++----- .../networking/HomeNetworkCommunications.h | 3 ++- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/program/Source/cloud/FTPAdapter.cpp b/program/Source/cloud/FTPAdapter.cpp index b95256b0..af6796d4 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 e58b1936..d6faea6c 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 2907d1bf..f9186758 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 81c43491..bd92a6c0 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 853c727c..37b88783 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 -- GitLab