| 54 | } |
| 55 | |
| 56 | static Status DoWriteStringToFile(Env* env, const Slice& data, const std::string& fname, |
| 57 | bool should_sync) { |
| 58 | WritableFile* file; |
| 59 | Status s = env->NewWritableFile(fname, &file, EnvOptions()); |
| 60 | if (!s.ok()) { |
| 61 | return s; |
| 62 | } |
| 63 | s = file->Append(data); |
| 64 | if (s.ok() && should_sync) { |
| 65 | s = file->Sync(); |
| 66 | } |
| 67 | if (s.ok()) { |
| 68 | s = file->Close(); |
| 69 | } |
| 70 | delete file; // Will auto-close if we did not close above |
| 71 | if (!s.ok()) { |
| 72 | env->DeleteFile(fname); |
| 73 | } |
| 74 | return s; |
| 75 | } |
| 76 | |
| 77 | Status WriteStringToFile(Env* env, const Slice& data, const std::string& fname) { |
| 78 | return DoWriteStringToFile(env, data, fname, false); |
no test coverage detected