Commit c08bccfd authored by Hélène Ortiz's avatar Hélène Ortiz

Add parameter 'addServerHome' to method saveFile in FileManager.

parent 2be271df
......@@ -543,6 +543,7 @@ message SaveFileRequest {
required string fileName = 2;
required uint32 fileType = 3;
required string content = 4;
required bool addServerHome = 5;
}
message GetFileContentRequest {
......
......@@ -3112,7 +3112,7 @@ bool CommandZoneResponder::processSaveFile(cameo::application::Request * request
common::BooleanResponse responseMessage;
FileManager::getInstance()->saveFile(messageRequest.filename(), messageRequest.content());
FileManager::getInstance()->saveFile(messageRequest.filename(), messageRequest.content(), messageRequest.addserverhome());
responseMessage.set_value(true);
// Serialize the response.
......
......@@ -96,20 +96,28 @@ std::string FileManager::getFileContent(const std::string& fileName) {
}
void FileManager::saveFile(const std::string& fileName, const std::string& content) {
void FileManager::saveFile(const std::string& fileName, const std::string& content, const bool addServerHome) {
cout << "FileManager::saveFile(" << fileName << ")" << endl;
string filePath;
if (addServerHome) {
filePath = _homePath + "/" + fileName;
} else {
filePath = fileName;
}
cout << "FileManager::saveFile(" << filePath << ")" << endl;
// Getting the path
size_t p = fileName.find_last_of('/');
size_t p = filePath.find_last_of('/');
if ((p >= 0) && (p < fileName.size())) {
string path = fileName.substr(0, p + 1);
if ((p >= 0) && (p < filePath.size())) {
string path = filePath.substr(0, p + 1);
if (!fs::exists(path)) {
fs::create_directory(path);
}
if (fs::exists(path)) {
fs::ofstream outFile(fileName.c_str(), ios::out);
fs::ofstream outFile(filePath.c_str(), ios::out);
outFile << content << endl;
cout << "FileManager::saveFile " << fileName << " saved!" << endl;
outFile.close();
......@@ -118,6 +126,7 @@ void FileManager::saveFile(const std::string& fileName, const std::string& conte
}
std::string FileManager::getTree(const std::string& rootDirectory, const std::string& extension) {
......
......@@ -72,7 +72,7 @@ public:
std::string getFileContent(const std::string& fileName);
void saveFile(const std::string& fileName, const std::string& content);
void saveFile(const std::string& fileName, const std::string& content, const bool addServerHome);
std::string getTree(const std::string& rootDirectory, const std::string& extension);
std::string getFileTree(const path currentPath, const std::string& extension, rapidjson::PrettyWriter<rapidjson::StringBuffer> &writer);
void deleteFile(const std::string& fileName);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment