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; }
DWORD WINAPI CGMP::udtRcvHandler(LPVOID s) #endif { CGMP* self = (CGMP*)s; Transport t; sockaddr_in addr; int namelen = sizeof(sockaddr_in); int32_t header[4]; while (!self->m_bClosed) { if (self->m_UDTSocket.accept(t, (sockaddr*)&addr, &namelen) < 0) continue; int port; if (t.recv((char*)&port, 4) < 0) { t.close(); continue; } // recv "header" information if (t.recv((char*)header, 16) < 0) { t.close(); continue; } CMsgRecord* rec = new CMsgRecord; char tmp[64]=""; udt_inet_ntop(AF_INET, &(addr.sin_addr), tmp, 64); rec->m_strIP = tmp; rec->m_iPort = port; rec->m_pMsg = new CGMPMessage; //rec->m_pMsg->m_iType = type; rec->m_pMsg->m_iSession = header[1]; rec->m_pMsg->m_iID = header[2]; rec->m_pMsg->m_iInfo = header[3]; // recv parameter size if (t.recv((char*)&(rec->m_pMsg->m_iLength), 4) < 0) { t.close(); delete rec->m_pMsg; delete rec; continue; } rec->m_pMsg->m_pcData = new char[rec->m_pMsg->m_iLength]; if (t.recv(rec->m_pMsg->m_pcData, rec->m_pMsg->m_iLength) < 0) { t.close(); delete rec->m_pMsg; delete rec; continue; } t.close(); if (self->m_PeerHistory.hit(rec->m_strIP, rec->m_iPort, rec->m_pMsg->m_iSession, rec->m_pMsg->m_iID)) continue; self->m_PeerHistory.insert(rec->m_strIP, rec->m_iPort, rec->m_pMsg->m_iSession, rec->m_pMsg->m_iID); if (0 == header[3]) { { CMutexGuard guard (self->m_RcvQueueLock); self->m_qRcvQueue.push(rec); } #ifndef WIN32 pthread_cond_signal(&self->m_RcvQueueCond); #else SetEvent(self->m_RcvQueueCond); #endif } else { { CMutexGuard guard (self->m_ResQueueLock); self->m_mResQueue[header[3]] = rec; } #ifndef WIN32 pthread_cond_signal(&self->m_ResQueueCond); #else SetEvent(self->m_ResQueueCond); #endif } } #ifndef WIN32 pthread_cond_signal(&self->m_RcvQueueCond); pthread_cond_signal(&self->m_ResQueueCond); #else SetEvent(self->m_RcvQueueCond); SetEvent(self->m_ResQueueCond); #endif return NULL; }
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; }