Only append new line if file is not empty

This commit is contained in:
2025-06-11 13:17:05 +02:00
parent 5333633d7c
commit 383c579db1

View File

@@ -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());
}; };