add sync function (alternative to ports -u)
fix printf when used with --regex
This commit is contained in:
parent
d9ec1c1e98
commit
de7e9b6a1e
6
INSTALL
6
INSTALL
@ -1,6 +1,6 @@
|
|||||||
Installing prt-get
|
Installing prt-get
|
||||||
------------------
|
------------------
|
||||||
Installing prt-get is just a matter of
|
Installing prt-get is just a matter of
|
||||||
./configure
|
meson setup bld --prefix=/usr
|
||||||
make
|
ninja -C bld
|
||||||
make install
|
ninja -C bld install
|
||||||
|
@ -128,7 +128,7 @@ const string& ArgParser::alternateConfigFile() const
|
|||||||
*/
|
*/
|
||||||
bool ArgParser::parse()
|
bool ArgParser::parse()
|
||||||
{
|
{
|
||||||
const int commandCount = 34;
|
const int commandCount = 35;
|
||||||
string commands[commandCount] = { "list", "search", "dsearch",
|
string commands[commandCount] = { "list", "search", "dsearch",
|
||||||
"info", "version", "cache",
|
"info", "version", "cache",
|
||||||
"depends", "install", "depinst",
|
"depends", "install", "depinst",
|
||||||
@ -139,7 +139,7 @@ bool ArgParser::parse()
|
|||||||
"fsearch", "lock", "unlock",
|
"fsearch", "lock", "unlock",
|
||||||
"listlocked", "cat", "ls", "edit",
|
"listlocked", "cat", "ls", "edit",
|
||||||
"remove", "deptree", "dumpconfig",
|
"remove", "deptree", "dumpconfig",
|
||||||
"listorphans" };
|
"listorphans", "sync" };
|
||||||
|
|
||||||
Type commandID[commandCount] = { LIST, SEARCH, DSEARCH, INFO,
|
Type commandID[commandCount] = { LIST, SEARCH, DSEARCH, INFO,
|
||||||
SHOW_VERSION, CREATE_CACHE,
|
SHOW_VERSION, CREATE_CACHE,
|
||||||
@ -150,7 +150,7 @@ bool ArgParser::parse()
|
|||||||
DEPENDENT, SYSUP, CURRENT,
|
DEPENDENT, SYSUP, CURRENT,
|
||||||
FSEARCH, LOCK, UNLOCK, LISTLOCKED,
|
FSEARCH, LOCK, UNLOCK, LISTLOCKED,
|
||||||
CAT, LS, EDIT, REMOVE, DEPTREE,
|
CAT, LS, EDIT, REMOVE, DEPTREE,
|
||||||
DUMPCONFIG, LISTORPHANS };
|
DUMPCONFIG, LISTORPHANS, SYNC };
|
||||||
if ( m_argc < 2 ) {
|
if ( m_argc < 2 ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
LISTINST, PRINTF, README, DEPENDENT, SYSUP,
|
LISTINST, PRINTF, README, DEPENDENT, SYSUP,
|
||||||
CURRENT, FSEARCH, LOCK, UNLOCK, LISTLOCKED,
|
CURRENT, FSEARCH, LOCK, UNLOCK, LISTLOCKED,
|
||||||
CAT, LS, EDIT, REMOVE,
|
CAT, LS, EDIT, REMOVE,
|
||||||
DEPTREE, DUMPCONFIG, LISTORPHANS };
|
DEPTREE, DUMPCONFIG, LISTORPHANS, SYNC };
|
||||||
|
|
||||||
bool isCommandGiven() const;
|
bool isCommandGiven() const;
|
||||||
bool isTest() const;
|
bool isTest() const;
|
||||||
|
@ -161,6 +161,9 @@ int main( int argc, char** argv )
|
|||||||
case ArgParser::LISTORPHANS:
|
case ArgParser::LISTORPHANS:
|
||||||
prtGet.listOrphans();
|
prtGet.listOrphans();
|
||||||
break;
|
break;
|
||||||
|
case ArgParser::SYNC:
|
||||||
|
prtGet.syncPorts();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
cerr << "unknown command" << endl;
|
cerr << "unknown command" << endl;
|
||||||
break;
|
break;
|
||||||
|
@ -70,8 +70,8 @@ PrtGet::PrtGet( const ArgParser* parser )
|
|||||||
m_pkgDB = new PkgDB(m_parser->installRoot());
|
m_pkgDB = new PkgDB(m_parser->installRoot());
|
||||||
readConfig();
|
readConfig();
|
||||||
|
|
||||||
m_useRegex = m_config->useRegex() || m_parser->useRegex();
|
m_useRegex = ( m_config->useRegex() || m_parser->useRegex() );
|
||||||
m_followSoftdeps = m_config->followSoftdeps() || m_parser->followSoftdeps();
|
m_followSoftdeps = ( m_config->followSoftdeps() || m_parser->followSoftdeps() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! destruct PrtGet object */
|
/*! destruct PrtGet object */
|
||||||
@ -1263,7 +1263,7 @@ void PrtGet::printf()
|
|||||||
assertExactArgCount(1);
|
assertExactArgCount(1);
|
||||||
|
|
||||||
initRepo();
|
initRepo();
|
||||||
string filter = m_parser->useRegex() ? "." : "*";
|
string filter = m_useRegex ? ".*" : "*";
|
||||||
if ( m_parser->hasFilter() ) {
|
if ( m_parser->hasFilter() ) {
|
||||||
filter = m_parser->filter();
|
filter = m_parser->filter();
|
||||||
}
|
}
|
||||||
@ -2294,3 +2294,81 @@ void PrtGet::dumpConfig()
|
|||||||
cout << endl;
|
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<string> 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<char*>::const_iterator itc = m_parser->otherArgs().begin();
|
||||||
|
list<string>::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<string> 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<string>::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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@ public:
|
|||||||
void printDiff();
|
void printDiff();
|
||||||
void printQuickDiff();
|
void printQuickDiff();
|
||||||
void listOrphans();
|
void listOrphans();
|
||||||
|
void syncPorts();
|
||||||
|
|
||||||
void createCache();
|
void createCache();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user