Only append new line if file is not empty
This commit is contained in:
@@ -22,8 +22,13 @@ void FileService::createOrOverwriteFile(std::string path, std::string content) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void FileService::appendToFile(std::string path, std::string content) {
|
void FileService::appendToFile(std::string path, std::string content) {
|
||||||
|
bool fileNotEmpty = FileService::doesNonEmptyFileExist(path);
|
||||||
std::stringstream cmd;
|
std::stringstream cmd;
|
||||||
cmd << ECHO_PATH << " \"" << "\n" << content << "\" >> " << path;
|
if (fileNotEmpty) {
|
||||||
|
cmd << ECHO_PATH << " \"" << "\n" << content << "\" >> " << path;
|
||||||
|
} else {
|
||||||
|
cmd << ECHO_PATH << " \"" << content << "\" >> " << path;
|
||||||
|
}
|
||||||
ShellService::exec(cmd.str().c_str());
|
ShellService::exec(cmd.str().c_str());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user