| 659 | } // namespace |
| 660 | |
| 661 | Status MockFileSystem::Move(const std::string& src, const std::string& dest) { |
| 662 | return BinaryOp::Run(impl_.get(), src, dest, [&](const BinaryOp& op) -> Status { |
| 663 | if (op.src_entry == nullptr) { |
| 664 | return PathNotFound(src); |
| 665 | } |
| 666 | if (op.dest_entry != nullptr) { |
| 667 | if (op.dest_entry->is_dir()) { |
| 668 | return Status::IOError("Cannot replace destination '", dest, |
| 669 | "', which is a directory"); |
| 670 | } |
| 671 | if (op.dest_entry->is_file() && op.src_entry->is_dir()) { |
| 672 | return Status::IOError("Cannot replace destination '", dest, |
| 673 | "', which is a file, with directory '", src, "'"); |
| 674 | } |
| 675 | } |
| 676 | if (op.src_parts.size() < op.dest_parts.size()) { |
| 677 | // Check if dest is a child of src |
| 678 | auto p = |
| 679 | std::mismatch(op.src_parts.begin(), op.src_parts.end(), op.dest_parts.begin()); |
| 680 | if (p.first == op.src_parts.end()) { |
| 681 | return Status::IOError("Cannot move '", src, "' into child path '", dest, "'"); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | // Move original entry, fix its name |
| 686 | std::unique_ptr<Entry> new_entry(new Entry(std::move(*op.src_entry))); |
| 687 | new_entry->SetName(op.dest_name); |
| 688 | bool deleted = op.src_dir.DeleteEntry(op.src_name); |
| 689 | DCHECK(deleted); |
| 690 | op.dest_dir.AssignEntry(op.dest_name, std::move(new_entry)); |
| 691 | return Status::OK(); |
| 692 | }); |
| 693 | } |
| 694 | |
| 695 | Status MockFileSystem::CopyFile(const std::string& src, const std::string& dest) { |
| 696 | return BinaryOp::Run(impl_.get(), src, dest, [&](const BinaryOp& op) -> Status { |
nothing calls this directly
no test coverage detected