Appends the given data to the specified file. It will create the file if it doesn't already exist.
| 37 | // Appends the given data to the specified file. It will create the file if it |
| 38 | // doesn't already exist. |
| 39 | Status AppendStringToFile(const std::string& fname, StringPiece data, |
| 40 | Env* env) { |
| 41 | // TODO(ckluk): If opening and closing on every log causes performance issues, |
| 42 | // we can reimplement using reference counters. |
| 43 | mutex_lock l(*file_mutex); |
| 44 | std::unique_ptr<WritableFile> file; |
| 45 | TF_RETURN_IF_ERROR(env->NewAppendableFile(fname, &file)); |
| 46 | Status a = file->Append(data); |
| 47 | Status c = file->Close(); |
| 48 | return a.ok() ? c : a; |
| 49 | } |
| 50 | |
| 51 | } // namespace |
| 52 |
no test coverage detected