void operator()(Uri &uri) const { uri.append(scheme); if (opaque_schemes::exists(scheme)) { uri.append(":"); } else { uri.append("://"); } }
void operator()(Uri &uri) const { std::string encoded_key, encoded_query; if (boost::empty(uri.query())) { uri.append("?"); } else { uri.append("&"); } uri.append(key_); uri.append("="); uri.append(query_); }
void operator()(Uri &uri) const { uri.append("?"); uri.append(query_); }
void operator () (Uri &uri) const { uri.append(host); }
void operator () (Uri &uri) const { uri.append(":"); uri.append(port); }
void operator () (Uri &uri) const { uri.append("#"); uri.append(fragment); }
void operator () (Uri &uri) const { uri.append(path); }
int CmdMerge::execute (std::string& output) { context.footnote ("The 'merge' command is deprecated, and will be removed in a subsequent release."); // invoke gc and commit before merging in order to update data files context.tdb2.gc (); context.tdb2.commit (); std::vector <std::string> words = context.a3.extract_words (); std::string file; if (words.size ()) file = words[0]; std::string pushfile = ""; std::string tmpfile = ""; std::string sAutopush = lowerCase (context.config.get ("merge.autopush")); bool bAutopush = context.config.getBoolean ("merge.autopush"); Uri uri (file, "merge"); uri.parse(); if (uri._data.length ()) { Directory location (context.config.get ("data.location")); // be sure that uri points to a file uri.append ("undo.data"); Transport* transport; if ((transport = Transport::getTransport (uri)) != NULL ) { tmpfile = location._data + "/undo_remote.data"; transport->recv (tmpfile); delete transport; file = tmpfile; } else file = uri._path; // XXX the following function could indicate whether a modification was // performed without an exception (by returning a boolean, within a status // object or with a specific function) try { context.tdb2.merge (file); } catch (const std::string& e) { if (e == STRING_TDB2_UP_TO_DATE) { output += e + "\n"; return 0; } else throw e; } output += std::string (STRING_CMD_MERGE_COMPLETE) + "\n"; if (tmpfile != "") remove (tmpfile.c_str ()); if (((sAutopush == "ask") && (confirm (format (STRING_CMD_MERGE_CONFIRM, uri.ToString ())))) || (bAutopush)) { // Derive autopush uri from merge.default.uri? otherwise: change prompt above // Change the "merge" command to "push". std::vector <Arg>::iterator i; for (i = context.a3.begin (); i != context.a3.end (); ++i) { if (i->_category == Arg::cat_command) { i->_raw = "push"; break; } } // Append the URI argument. context.a3.push_back (Arg (uri._data, Arg::cat_literal)); std::string out; assert (context.commands["push"]); context.commands["push"]->execute (out); } } else throw std::string (STRING_CMD_MERGE_NO_URI); return 0; }
int CmdPull::execute (std::string& output) { context.footnote ("The 'pull' command is deprecated, and will be removed in a subsequent release."); std::vector <std::string> words = context.a3.extract_words (); std::string file; if (words.size ()) file = words[0]; Uri uri (file, "pull"); uri.parse (); if (uri._data.length ()) { Directory location (context.config.get ("data.location")); if (! uri.append ("{pending,undo,completed}.data")) throw format (STRING_CMD_PULL_NOT_DIR, uri._path); Transport* transport; if ((transport = Transport::getTransport (uri)) != NULL) { transport->recv (location._data + "/"); delete transport; } else { // Verify that files are not being copied from rc.data.location to the // same place. if (Directory (uri._path) == Directory (context.config.get ("data.location"))) throw std::string (STRING_CMD_PULL_SAME); // copy files locally // remove {pending,undo,completed}.data uri._path = uri.parent(); Path path1 (uri._path + "undo.data"); Path path2 (uri._path + "pending.data"); Path path3 (uri._path + "completed.data"); if (path1.exists() && path2.exists() && path3.exists()) { // if (confirm ("xxxxxxxxxxxxx")) // { std::ofstream ofile1 ((location._data + "/undo.data").c_str(), std::ios_base::binary); std::ifstream ifile1 (path1._data.c_str() , std::ios_base::binary); ofile1 << ifile1.rdbuf(); std::ofstream ofile2 ((location._data + "/pending.data").c_str(), std::ios_base::binary); std::ifstream ifile2 (path2._data.c_str() , std::ios_base::binary); ofile2 << ifile2.rdbuf(); std::ofstream ofile3 ((location._data + "/completed.data").c_str(), std::ios_base::binary); std::ifstream ifile3 (path3._data.c_str() , std::ios_base::binary); ofile3 << ifile3.rdbuf(); // } } else { throw format (STRING_CMD_PULL_MISSING, uri._path); } } output += format (STRING_CMD_PULL_TRANSFERRED, uri.ToString ()) + "\n"; } else throw std::string (STRING_CMD_PULL_NO_URI); return 0; }
void operator () (Uri &uri) const { uri.append(authority); }
void operator () (Uri &uri) const { uri.append(user_info); uri.append("@"); }