| 617 | |
| 618 | template <typename OpFunc> |
| 619 | static Status Run(MockFileSystem::Impl* impl, const std::string& src, |
| 620 | const std::string& dest, OpFunc&& op_func) { |
| 621 | RETURN_NOT_OK(ValidatePath(src)); |
| 622 | RETURN_NOT_OK(ValidatePath(dest)); |
| 623 | auto src_parts = SplitAbstractPath(src); |
| 624 | auto dest_parts = SplitAbstractPath(dest); |
| 625 | RETURN_NOT_OK(ValidateAbstractPathParts(src_parts)); |
| 626 | RETURN_NOT_OK(ValidateAbstractPathParts(dest_parts)); |
| 627 | |
| 628 | auto guard = impl->lock_guard(); |
| 629 | |
| 630 | // Both source and destination must have valid parents |
| 631 | Entry* src_parent = impl->FindParent(src_parts); |
| 632 | if (src_parent == nullptr || !src_parent->is_dir()) { |
| 633 | return PathNotFound(src); |
| 634 | } |
| 635 | Entry* dest_parent = impl->FindParent(dest_parts); |
| 636 | if (dest_parent == nullptr || !dest_parent->is_dir()) { |
| 637 | return PathNotFound(dest); |
| 638 | } |
| 639 | Directory& src_dir = src_parent->as_dir(); |
| 640 | Directory& dest_dir = dest_parent->as_dir(); |
| 641 | DCHECK_GE(src_parts.size(), 1); |
| 642 | DCHECK_GE(dest_parts.size(), 1); |
| 643 | const auto& src_name = src_parts.back(); |
| 644 | const auto& dest_name = dest_parts.back(); |
| 645 | |
| 646 | BinaryOp op{std::move(src_parts), |
| 647 | std::move(dest_parts), |
| 648 | src_dir, |
| 649 | dest_dir, |
| 650 | src_name, |
| 651 | dest_name, |
| 652 | src_dir.Find(src_name), |
| 653 | dest_dir.Find(dest_name)}; |
| 654 | |
| 655 | return op_func(std::move(op)); |
| 656 | } |
| 657 | }; |
| 658 | |
| 659 | } // namespace |