MCPcopy Create free account
hub / github.com/apache/arrow / OpenOutputStream

Method OpenOutputStream

cpp/src/arrow/filesystem/mockfs.cc:384–415  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

382 }
383
384 Result<std::shared_ptr<io::OutputStream>> OpenOutputStream(
385 const std::string& path, bool append,
386 const std::shared_ptr<const KeyValueMetadata>& metadata) {
387 ARROW_RETURN_NOT_OK(internal::AssertNoTrailingSlash(path));
388 auto parts = SplitAbstractPath(path);
389 RETURN_NOT_OK(ValidateAbstractPathParts(parts));
390
391 Entry* parent = FindParent(parts);
392 if (parent == nullptr || !parent->is_dir()) {
393 return PathNotFound(path);
394 }
395 // Find the file in the parent dir, or create it
396 const auto& name = parts.back();
397 Entry* child = parent->as_dir().Find(name);
398 File* file;
399 if (child == nullptr) {
400 child = new Entry(File(current_time, name));
401 parent->as_dir().AssignEntry(name, std::unique_ptr<Entry>(child));
402 file = &child->as_file();
403 } else if (child->is_file()) {
404 file = &child->as_file();
405 file->mtime = current_time;
406 } else {
407 return NotAFile(path);
408 }
409 file->metadata = metadata;
410 auto ptr = std::make_shared<MockFSOutputStream>(file, pool);
411 if (append && file->data) {
412 RETURN_NOT_OK(ptr->Write(file->data->data(), file->data->size()));
413 }
414 return ptr;
415 }
416
417 Result<std::shared_ptr<io::BufferReader>> OpenInputReader(const std::string& path) {
418 ARROW_RETURN_NOT_OK(internal::AssertNoTrailingSlash(path));

Callers

nothing calls this directly

Calls 14

AssertNoTrailingSlashFunction · 0.85
SplitAbstractPathFunction · 0.85
is_dirMethod · 0.80
backMethod · 0.80
AssignEntryMethod · 0.80
is_fileMethod · 0.80
PathNotFoundFunction · 0.70
FileClass · 0.70
NotAFileFunction · 0.70
FindMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected