2 Commits

Author SHA1 Message Date
9619657f17 update man-page to document the sync command 2023-12-04 01:04:14 +00:00
de7e9b6a1e add sync function (alternative to ports -u)
fix printf when used with --regex
2023-12-02 13:59:40 +00:00
8 changed files with 136 additions and 9 deletions

View File

@@ -1,7 +1,6 @@
Installing prt-get
------------------
Installing prt-get is just a matter of
meson setup bld --prefix=/usr
cd bld && meson compile
meson install
ninja -C bld
ninja -C bld install

View File

@@ -115,6 +115,18 @@ See the \fBEXAMPLES\fP section below for details.
.B remove <package1> [<package2> ...]
Remove packages listed in this order
.TP
.B sync [\-\-install\-root=<dir>] [collection1 ... collectionN]
Reach out to remote servers defined in \fB/etc/ports\fP (or \fB<dir>/etc/ports\fP if
\-\-install\-root is given), and bring the local ports collections up to date. The sync
command processes all sync files whose suffix matches an executable file in
\fB/etc/ports/drivers\fP, unless specific collections are passed as arguments, in which case
only those collections are synchronized. If the same collection is listed in \fB/etc/ports\fP
with different suffixes, then the matching drivers are called in lexographic order. This
feature allows for multi-stage processing, e.g. if you want to apply local patches and then
update the manifests. For further details on the ports system and the format of the
{httpup,rsync,git} files, see \fBports(8)\fB.
.TP
.B sysup [\-\-softdeps] [\-\-nodeps]
Update all installed packages which are outdated. Sorts by hard dependencies

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -213,16 +213,50 @@ void Package::load() const
StringHelper::replaceAll( softdeps, " ", "," );
StringHelper::replaceAll( softdeps, ",,", "," );
StringHelper::replaceAll( softdeps, "(", "" );
StringHelper::replaceAll( softdeps, ")", "" );
// TODO: decide which one to use
#if 0
// remove commented out packages
list<string> softDepList = StringHelper::split( softdeps, ',' );
list<string>::iterator it = deps.begin();
for ( ; it != softDepList.end(); ++it ) {
if ( (*it)[0] == '#' ) {
cerr << "Commented dep: " << *it << endl;
} else {
if ( it != softDepsList.begin() ) {
m_data->optionals += ",";
}
m_data->optionals += *it;
}
}
#else
m_data->optionals = softdeps;
#endif
} else if ( startsWithNoCase( line, "dep" ) ) {
string depends = stripWhiteSpace( getValue( line, ':' ) );
StringHelper::replaceAll( depends, " ", "," );
StringHelper::replaceAll( depends, ",,", "," );
// TODO: decide which one to use
#if 0
// remove commented out packages
list<string> deps = StringHelper::split( depends, ',' );
list<string>::iterator it = deps.begin();
for ( ; it != deps.end(); ++it ) {
if ( (*it)[0] == '#' ) {
cerr << "Commented dep: " << *it << endl;
} else {
if ( it != deps.begin() ) {
m_data->depends += ",";
}
m_data->depends += *it;
}
}
#else
m_data->depends = depends;
#endif
}
}
}

View File

@@ -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<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;
}
}
}
}

View File

@@ -71,6 +71,7 @@ public:
void printDiff();
void printQuickDiff();
void listOrphans();
void syncPorts();
void createCache();