+basis::outcome file_transfer_tentacle::handle_build_target_tree_request(file_transfer_infoton &req,
+ const octopus_request_id &item_id)
+{
+ FUNCDEF("handle_build_target_tree_request");
+
+ // get the mapping from the specified location on this side.
+ filename splitting(req._src_root);
+ string_array pieces;
+ bool rooted;
+ splitting.separate(rooted, pieces);
+ astring source_mapping = pieces[0];
+
+ // patch the name up to find the sub_path for the source.
+ filename source_start;
+ pieces.zap(0, 0);
+ source_start.join(rooted, pieces);
+
+ // locate the allowed transfer depot for the mapping they provided.
+ file_transfer_record *mapping_record = _correspondences->find_mapping(source_mapping);
+ if (!mapping_record) {
+ LOG(astring("could not find source mapping of ") + source_mapping);
+ return NOT_FOUND;
+ }
+
+ // unpack the tree that they sent us which describes their local area.
+ directory_tree *dest_tree = new directory_tree;
+ if (!dest_tree->unpack(req._packed_data)) {
+ LOG(astring("could not unpack requester's directory tree"));
+ WHACK(dest_tree);
+ return GARBAGE;
+ }
+
+ string_array requested_names;
+ if (!requested_names.unpack(req._packed_data)) {
+ LOG(astring("could not unpack requester's filename includes"));
+ WHACK(dest_tree);
+ return GARBAGE;
+ }
+
+ // look up to see if this is about something that has already been seen.
+ // we don't want to add a new transfer record if they're already working on
+ // this. that also lets them do a new tree compare to restart the transfer.
+ file_transfer_record *the_rec = _transfers->find(item_id._entity,
+ req._src_root, req._dest_root);
+ if (!the_rec) {
+ // there was no existing record; we'll create a new one.
+ the_rec = new file_transfer_record;
+ the_rec->_ent = item_id._entity;
+ the_rec->_src_root = req._src_root;
+ the_rec->_dest_root = req._dest_root;
+ _transfers->append(the_rec);
+ } else {
+ // record some activity on this record.
+ the_rec->_done = false;
+ the_rec->_last_active.reset();
+ }
+
+ // create any directories that are missing at this point.
+ basis::outcome result = dest_tree->make_directories(req._dest_root);
+ if (result != common::OKAY) {
+ LOG("ERROR: got bad result from make_directories!");
+ }
+
+ req._packed_data.reset(); // clear out existing stuff before cloning.
+ file_transfer_infoton *reply = dynamic_cast<file_transfer_infoton *>(req.clone());
+
+ reply->_request = false; // it's a response now.
+ reply->_success = result;
+ store_product(reply, item_id);
+ // send back the comparison list.
+
+ return OKAY;
+}
+
+basis::outcome file_transfer_tentacle::handle_build_target_tree_response(file_transfer_infoton &resp,
+ const octopus_request_id &item_id)
+{
+//go to next step, tree comparison.
+//look at the handle tree compare response for help though.
+ FUNCDEF("handle_build_target_tree_response");
+ file_transfer_record *the_rec = _transfers->find(item_id._entity,
+ resp._src_root, resp._dest_root);
+ if (!the_rec) {
+ LOG(astring("could not find the record for this transfer: item=")
+ + item_id.text_form() + " src=" + resp._src_root + " dest="
+ + resp._dest_root);
+ return NOT_FOUND; // not registered, so reject it.
+ }
+
+ the_rec->_last_active.reset(); // record some activity on this record.
+
+ return resp._success;
+}
+