diff --git a/INSTALL b/INSTALL index 81b43f2..25721a4 100644 --- a/INSTALL +++ b/INSTALL @@ -1,6 +1,6 @@ Installing prt-get ------------------ Installing prt-get is just a matter of -./configure -make -make install +meson setup bld --prefix=/usr +ninja -C bld +ninja -C bld install diff --git a/src/argparser.cpp b/src/argparser.cpp index 79ec5df..7c5989e 100644 --- a/src/argparser.cpp +++ b/src/argparser.cpp @@ -128,7 +128,7 @@ const string& ArgParser::alternateConfigFile() const */ bool ArgParser::parse() { - const int commandCount = 34; + const int commandCount = 35; string commands[commandCount] = { "list", "search", "dsearch", "info", "version", "cache", "depends", "install", "depinst", @@ -139,7 +139,7 @@ bool ArgParser::parse() "fsearch", "lock", "unlock", "listlocked", "cat", "ls", "edit", "remove", "deptree", "dumpconfig", - "listorphans" }; + "listorphans", "sync" }; Type commandID[commandCount] = { LIST, SEARCH, DSEARCH, INFO, SHOW_VERSION, CREATE_CACHE, @@ -150,7 +150,7 @@ bool ArgParser::parse() DEPENDENT, SYSUP, CURRENT, FSEARCH, LOCK, UNLOCK, LISTLOCKED, CAT, LS, EDIT, REMOVE, DEPTREE, - DUMPCONFIG, LISTORPHANS }; + DUMPCONFIG, LISTORPHANS, SYNC }; if ( m_argc < 2 ) { return false; } diff --git a/src/argparser.h b/src/argparser.h index 44bfe4a..7adfa1f 100644 --- a/src/argparser.h +++ b/src/argparser.h @@ -38,7 +38,7 @@ public: LISTINST, PRINTF, README, DEPENDENT, SYSUP, CURRENT, FSEARCH, LOCK, UNLOCK, LISTLOCKED, CAT, LS, EDIT, REMOVE, - DEPTREE, DUMPCONFIG, LISTORPHANS }; + DEPTREE, DUMPCONFIG, LISTORPHANS, SYNC }; bool isCommandGiven() const; bool isTest() const; diff --git a/src/main.cpp b/src/main.cpp index c1af3f1..e430201 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -161,6 +161,9 @@ int main( int argc, char** argv ) case ArgParser::LISTORPHANS: prtGet.listOrphans(); break; + case ArgParser::SYNC: + prtGet.syncPorts(); + break; default: cerr << "unknown command" << endl; break; diff --git a/src/prtget.cpp b/src/prtget.cpp index a11a639..59c6931 100644 --- a/src/prtget.cpp +++ b/src/prtget.cpp @@ -70,8 +70,8 @@ PrtGet::PrtGet( const ArgParser* parser ) m_pkgDB = new PkgDB(m_parser->installRoot()); readConfig(); - m_useRegex = m_config->useRegex() || m_parser->useRegex(); - m_followSoftdeps = m_config->followSoftdeps() || m_parser->followSoftdeps(); + m_useRegex = ( m_config->useRegex() || m_parser->useRegex() ); + m_followSoftdeps = ( m_config->followSoftdeps() || m_parser->followSoftdeps() ); } /*! destruct PrtGet object */ @@ -1263,7 +1263,7 @@ void PrtGet::printf() assertExactArgCount(1); initRepo(); - string filter = m_parser->useRegex() ? "." : "*"; + string filter = m_useRegex ? ".*" : "*"; if ( m_parser->hasFilter() ) { filter = m_parser->filter(); } @@ -2294,3 +2294,81 @@ void PrtGet::dumpConfig() cout << endl; } } + +void PrtGet::syncPorts() +{ + const string sup_path = m_parser->installRoot() + "/etc/ports"; + const string driver_path = sup_path + "/drivers"; + DIR* d = opendir(driver_path.c_str()); + if (d == NULL) { + cerr << "Ports drivers directory " << driver_path.c_str() + << " not found. Aborting sync." << endl; + m_returnValue = PG_GENERAL_ERROR; + return; + } + struct dirent* de; + struct stat buf; + list drivers; + while ( (de = readdir(d)) ) { + string drvName = de->d_name; + if (drvName != "." && drvName != ".." && stat((driver_path + "/" + drvName).c_str(), &buf) == 0 + && buf.st_mode & S_IXUSR ) { + drivers.push_back(drvName); + } + } + closedir(d); + + if (drivers.size() == 0) { + cerr << "No valid ports drivers. Aborting sync." << endl; + m_returnValue = PG_GENERAL_ERROR; + return; + } + + if (m_parser->otherArgs().size()) { // sync selected repositories, with + drivers.sort(); // multi-stage processing done predictably + bool repo_active; + list::const_iterator itc = m_parser->otherArgs().begin(); + list::const_iterator itd; + for (; itc != m_parser->otherArgs().end(); ++itc) { + repo_active = false; + for (itd = drivers.begin(); itd != drivers.end(); ++itd) { + if (stat((sup_path + "/" + *itc + "." + *itd).c_str(),&buf) == 0) { + repo_active = true; + Process syncProc( driver_path + "/" + *itd, + sup_path + "/" + *itc + "." + *itd, -1 ); + if (syncProc.execute()) { + m_returnValue = PG_GENERAL_ERROR; + } + } + if (! repo_active) { + cerr << *itc << ": not a valid port collection" << endl; + } + } + } + } else { // sync all active repositories + list activeRepos; + size_t pos; + d = opendir(sup_path.c_str()); + while ( (de = readdir(d)) ) { + string rName = de->d_name; + pos = rName.find_last_of("."); + if ( pos != string::npos && find(drivers.begin(), drivers.end(), + rName.substr(pos+1)) != drivers.end() ) { + activeRepos.push_back(rName); + } + } + closedir(d); + + activeRepos.sort(); + list::const_iterator ite = activeRepos.begin(); + for ( ; ite != activeRepos.end(); ++ite) { + pos = (*ite).find_last_of("."); + Process syncProc( driver_path + "/" + (*ite).substr(pos+1), + sup_path + "/" + *ite, -1 ); + if (syncProc.execute()) { + m_returnValue = PG_GENERAL_ERROR; + } + } + } +} + diff --git a/src/prtget.h b/src/prtget.h index 9356a4b..b04e6d0 100644 --- a/src/prtget.h +++ b/src/prtget.h @@ -71,6 +71,7 @@ public: void printDiff(); void printQuickDiff(); void listOrphans(); + void syncPorts(); void createCache();