MCPcopy Create free account
hub / github.com/bytedance/bolt / LocalWriteFile

Method LocalWriteFile

bolt/common/file/File.cpp:264–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264LocalWriteFile::LocalWriteFile(
265 std::string_view path,
266 bool shouldCreateParentDirectories,
267 bool shouldThrowOnFileAlreadyExists) {
268 auto dir = fs::path(path).parent_path();
269 if (shouldCreateParentDirectories && !fs::exists(dir)) {
270 BOLT_CHECK(
271 common::generateFileDirectory(dir.c_str()),
272 "Failed to generate file directory");
273 }
274
275 std::unique_ptr<char[]> buf(new char[path.size() + 1]);
276 buf[path.size()] = 0;
277 memcpy(buf.get(), path.data(), path.size());
278 {
279 if (shouldThrowOnFileAlreadyExists) {
280 FILE* exists = fopen(buf.get(), "rb");
281 if (exists) {
282 fclose(exists);
283 BOLT_FAIL("Failure in LocalWriteFile: path '{}' already exists.", path);
284 }
285 }
286 }
287 auto* file = fopen(buf.get(), "ab");
288 BOLT_CHECK_NOT_NULL(
289 file,
290 "fopen failure in LocalWriteFile constructor, {} {}.",
291 path,
292 folly::errnoStr(errno));
293 file_ = file;
294}
295
296LocalWriteFile::~LocalWriteFile() {
297 try {

Callers

nothing calls this directly

Calls 5

generateFileDirectoryFunction · 0.85
memcpyFunction · 0.85
sizeMethod · 0.45
getMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected