Cards_install::Cards_install(const CardsArgumentParser& argParser, const std::string& configFileName) : Pkginst("cards install",configFileName),m_argParser(argParser) { parseArguments(); for( auto i : m_argParser.otherArguments() ) { if ( getListOfPackagesFromCollection(i).empty() && (! checkBinaryExist(i) ) ) { m_actualError = PACKAGE_NOT_FOUND; treatErrors(i); } } Pkgrepo::parseConfig(configFileName, m_config); buildDatabaseWithNameVersion(); for( auto i : m_argParser.otherArguments() ) { std::set<std::string> ListOfPackage = getListOfPackagesFromCollection(i); if ( (!ListOfPackage.empty()) && (!checkBinaryExist(i)) ) { for (auto i : ListOfPackage ) { if (checkPackageNameExist(i)) continue; m_packageName = i; generateDependencies(); } } else { m_packageName = i; generateDependencies(); } } getLocalePackagesList(); for ( auto i : m_dependenciesList ) { m_packageArchiveName = getPackageFileName(i); ArchiveUtils packageArchive(m_packageArchiveName.c_str()); std::string name = packageArchive.name(); if ( checkPackageNameExist(name )) { m_upgrade=1; } else { m_upgrade=0; } run(); } }
void Cards_create::createBinaries(const string& configFileName, const string& packageName) { Config config; Pkgrepo::parseConfig(configFileName, config); cout << "create of " << packageName << endl; string pkgdir = getPortDir(packageName); if (pkgdir == "" ) { m_actualError = PACKAGE_NOT_FOUND; treatErrors(packageName); } string timestamp; string commandName = "cards create: "; string message; int fdlog = -1; if ( config.logdir != "" ) { if ( ! createRecursiveDirs(config.logdir) ) { m_actualError = CANNOT_CREATE_DIRECTORY; treatErrors(config.logdir); } string logFile = config.logdir + "/" + packageName + ".log"; unlink( logFile.c_str() ); fdlog = open(logFile.c_str(),O_APPEND | O_WRONLY | O_CREAT, 0666 ); if ( fdlog == -1 ) { m_actualError = CANNOT_OPEN_FILE; treatErrors(logFile); } } message = commandName + pkgdir + " package(s)"; cout << message << endl; if ( config.logdir != "" ) { write( fdlog, message.c_str(), message.length()); time_t startTime; time(&startTime); timestamp = ctime(&startTime); timestamp = " starting build " + timestamp; write( fdlog, timestamp.c_str(), timestamp.length()); write( fdlog, "\n", 1 ); } chdir( pkgdir.c_str() ); string runscriptCommand = "sh"; string cmd = "pkgmk"; string args = "-d "; process makeprocess( cmd, args, fdlog ); int result = 0 ; result = makeprocess.executeShell(); #ifndef NDEBUG cerr << result << endl; #endif switch ( result ) { case 1: throw runtime_error("General error"); break; case 2: throw runtime_error("Error Invalid Pkgfile"); break; case 3: throw runtime_error("Error Sources /build directory missing or missing read/write permission"); break; case 4: throw runtime_error("Error during download of sources file(s)"); break; case 5: throw runtime_error("Error during unpacking of sources file(s)"); break; case 6: throw runtime_error("Error md5sum from sources Checking"); break; case 7: throw runtime_error("Error footprint Checking"); break; case 8: throw runtime_error("Error while running 'build()'"); break; case 10: throw runtime_error("Error searching runtime dependancies"); break; case 11: throw runtime_error(pkgdir + "/" + m_packageName +".info not found"); break; } if (result > 0) { //TODO find out why return code is wrong m_actualError = CANNOT_PARSE_FILE; treatErrors(pkgdir+ "/Pkgfile"); } if ( config.logdir != "" ) { time_t endTime; time(&endTime); timestamp = ctime(&endTime); timestamp = commandName + "build done " + timestamp; write( fdlog, "\n", 1 ); write( fdlog, timestamp.c_str(), timestamp.length()); write( fdlog, "\n", 1 ); } std::set<string> listOfPackages; if (findFile(listOfPackages, pkgdir) != 0) { m_actualError = CANNOT_READ_DIRECTORY; treatErrors(pkgdir); } // Let's install the found binaries now for (auto i : listOfPackages) { if (i.find("cards.tar")== string::npos ) continue; m_packageFileName = pkgdir + "/" + i; ArchiveUtils packageArchive(m_packageFileName.c_str()); string name = packageArchive.name(); string version = packageArchive.version(); message = "CREATED: " + name + " " + version; m_upgrade=0; buildDatabaseWithNameVersion(); if ( checkPackageNameExist(name) ) { message = name + ": is ALLREADY installed"; m_upgrade=1; } m_packageArchiveName = pkgdir + "/" + i; run(); cout << message << endl; if ( config.logdir != "" ) { write( fdlog, message.c_str(), message.length()); write( fdlog, "\n", 1 ); } } if ( config.logdir != "" ) { time_t finishTime; time(&finishTime); timestamp = ctime(&finishTime); timestamp = commandName + "finish " + timestamp; write( fdlog, "\n", 1 ); write( fdlog, timestamp.c_str(), timestamp.length()); write( fdlog, "\n", 1 ); close ( fdlog ); } }
void Pkginfo::run() { if (m_archiveinfo) { pair<string, pkginfo_t> packageArchive = openArchivePackage(m_packageArchiveName) ; cout << packageArchive.first << " Description : " << packageArchive.second.description << endl << packageArchive.first << " URL : " << packageArchive.second.url << endl << packageArchive.first << " Maintainer(s) : " << packageArchive.second.maintainer << endl << packageArchive.first << " Packager(s) : " << packageArchive.second.packager << endl << packageArchive.first << " Version : " << packageArchive.second.version << endl << packageArchive.first << " Release : " << packageArchive.second.release << endl << packageArchive.first << " Architecture : " << packageArchive.second.arch << endl << packageArchive.first << " Build date : " << packageArchive.second.build << endl; if (packageArchive.second.dependencies.size() > 0 ) { cout << packageArchive.first << " Dependencies : "; for ( auto i : packageArchive.second.dependencies) cout << i.first << i.second << " "; cout << endl; } } // Make footprint if (m_footprint_mode) { getFootprintPackage(m_arg); } else { // Modes that require the database to be opened Db_lock lock(m_root, false); getListOfPackageNames(m_root); if (m_installed_mode) { // List installed packages buildDatabaseWithNameVersion(); for (auto i : m_listOfInstPackages) { cout << i.first << " " << i.second.version << "-" << i.second.release << endl; } } else if (m_list_mode) { // List package or file contents buildDatabaseWithDetailsInfos(false); if (checkPackageNameExist(m_arg)) { copy(m_listOfInstPackages[m_arg].files.begin(), m_listOfInstPackages[m_arg].files.end(), ostream_iterator<string>(cout, "\n")); } else if (checkFileExist(m_arg)) { pair<string, pkginfo_t> package = openArchivePackage(m_arg); copy(package.second.files.begin(), package.second.files.end(), ostream_iterator<string>(cout, "\n")); } else { m_actualError = NOT_INSTALL_PACKAGE_NEITHER_PACKAGE_FILE; treatErrors(m_arg); } } else if (m_runtimedependencies_mode) { /* Get runtimedependencies of the file found in the directory path get the list of installed package silently */ buildDatabaseWithDetailsInfos(true); regex_t r; int Result; regcomp(&r, ".", REG_EXTENDED | REG_NOSUB); set<string>filenameList; Result = findRecursiveFile (filenameList, const_cast<char*>(m_arg.c_str()), &r, WS_DEFAULT); // get the list of library for all the possible files set<string> librariesList; for (auto i : filenameList) Result = getRuntimeLibrariesList(librariesList,i); // get the own package for all the elf files dependencies libraries #ifndef NDEBUG for (auto i : librariesList) cerr << i <<endl; #endif if ( (librariesList.size() > 0 ) && (Result > -1) ) { set<string> runtimeList; for (set<string>::const_iterator i = librariesList.begin();i != librariesList.end();++i) { for (packages_t::const_iterator j = m_listOfInstPackages.begin(); j != m_listOfInstPackages.end();++j) { bool found = false; for (set<string>::const_iterator k = j->second.files.begin(); k != j->second.files.end(); ++k) { if ( k->find('/' + *i) != string::npos) { string dependency = j->first + static_cast<ostringstream*>( &(ostringstream() << j->second.build ))->str(); runtimeList.insert(dependency); break; found = true; } } if ( found == true) { found = false; break; } } } if (runtimeList.size()>0) { #ifndef NDEBUG cerr << "Number of libraries founds: " << runtimeList.size() << endl; #endif unsigned int s = 1; for ( auto i : runtimeList ) { cout << i << endl; s++; } cout << endl; } } } else if (m_libraries_mode + m_runtime_mode > 0) { // get the list of installed package silently buildDatabaseWithDetailsInfos(true); set<string> librariesList; int Result = -1; if (checkPackageNameExist(m_arg)) { for (set<string>::const_iterator i = m_listOfInstPackages[m_arg].files.begin(); i != m_listOfInstPackages[m_arg].files.end(); ++i){ string filename('/' + *i); Result = getRuntimeLibrariesList(librariesList,filename); } if ( (librariesList.size() > 0 ) && (Result > -1) ) { if (m_runtime_mode) { set<string> runtimeList; for (set<string>::const_iterator i = librariesList.begin(); i != librariesList.end(); ++i) { for (packages_t::const_iterator j = m_listOfInstPackages.begin(); j != m_listOfInstPackages.end(); ++j){ bool found = false; for (set<string>::const_iterator k = j->second.files.begin(); k != j->second.files.end(); ++k) { if ( k->find('/' + *i) != string::npos) { runtimeList.insert(j->first); break; found = true; } } if (found == true) { found = false; break; } } } if (runtimeList.size()>0) { unsigned int s = 1; for (set<string>::const_iterator i = runtimeList.begin(); i!=runtimeList.end(); ++i){ cout << *i; s++; if (s <= runtimeList.size()) cout << ","; } cout << endl; } } else { for (set<string>::const_iterator i = librariesList.begin();i != librariesList.end();++i) cout << *i << endl; } } } } else if (m_epoc) { // get the building time of the package return 0 if not found buildDatabaseWithDetailsInfos(true); if (checkPackageNameExist(m_arg)) { cout << m_listOfInstPackages[m_arg].build << endl; } else { cout << "0" << endl; } } else if (m_details_mode) { // get all the details of a package buildDatabaseWithDetailsInfos(false); if (checkPackageNameExist(m_arg)) { char * c_time_s = ctime(&m_listOfInstPackages[m_arg].build); cout << "Name : " << m_arg << endl << "Description : " << m_listOfInstPackages[m_arg].description << endl << "URL : " << m_listOfInstPackages[m_arg].url << endl << "Maintainer(s) : " << m_listOfInstPackages[m_arg].maintainer << endl << "Packager(s) : " << m_listOfInstPackages[m_arg].packager << endl << "Version : " << m_listOfInstPackages[m_arg].version << endl << "Release : " << m_listOfInstPackages[m_arg].release << endl << "Build date : " << c_time_s << "Size : " << m_listOfInstPackages[m_arg].size << endl << "Number of Files: " << m_listOfInstPackages[m_arg].files.size()<< endl << "Arch : " << m_listOfInstPackages[m_arg].arch << endl; if ( m_listOfInstPackages[m_arg].dependencies.size() > 0 ) { cout << "Dependencies : "; for ( auto i : m_listOfInstPackages[m_arg].dependencies) cout << i.first << " "; cout << endl; } } } else if (m_owner_mode) { // List owner(s) of file or directory buildDatabaseWithDetailsInfos(false); regex_t preg; if (regcomp(&preg, m_arg.c_str(), REG_EXTENDED | REG_NOSUB)) { m_actualError = CANNOT_COMPILE_REGULAR_EXPRESSION; treatErrors(m_arg); } vector<pair<string, string> > result; result.push_back(pair<string, string>("Package", "File")); unsigned int width = result.begin()->first.length(); // Width of "Package" #ifndef NDEBUG cerr << m_arg << endl; #endif for (auto i : m_listOfInstPackages) { for (auto j : i.second.files) { const string file('/' + j); if (!regexec(&preg, file.c_str(), 0, 0, 0)) { result.push_back(pair<string, string>(i.first, j)); if (i.first.length() > width) { width = i.first.length(); } } } } regfree(&preg); if (result.size() > 1) { for (auto i : result ) { cout << left << setw(width + 2) << i.first << i.second << endl; } } else { cout << m_utilName << ": no owner(s) found" << endl; } } } }